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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With