views:

57

answers:

2

In my app I'm creating folders for archiving old stuff from a harddisc.

When creating a new folder I must copy all NTFS rights (Groups / Users) from the source folder to the newly created destination folder.

Here is what I've written so far:

FileSecurity fileSecurity =
    File.GetAccessControl(filenameSource, AccessControlSections.All);
FileAttributes fileAttributes = File.GetAttributes(filenameSource);
File.SetAccessControl(filenameDest, fileSecurity);
File.SetAttributes(filenameDest, fileAttributes);

Is this really all I ought to do or am I missing something important?

+1  A: 

If that is a folder, then you may would want to check Directory.SetAccessControl() Method. You may would want to call DirectorySecurity.SetAccessRuleProtection(isProtected/*true*/,preserveInheritance /*false*/) if you want to prevent the files from inheriting ACL rules, before calling Directory.SetAccessControl();

KMan
A: 

Why not create a Process and call the XCOPY command? It can copy permissions.

nickyt
Because I need it in my own application created in C#.Net ;-) Thanks for trying to help.
dhh