I\'m writing a DLL to change permissions on a folder and everything underneath the folder. Below is the code that I have right now.
The problem comes when I call ad
You have to do it recursively. You can specify inheritance rules for new folders/files but for existing you have to do it yourself.
This question is old but I was looking for the same thing and found a solution:
var dirInfo = new DirectoryInfo(dirName);
var dirSecurity = dirInfo.GetAccessControl();
// Add the DirectorySystemAccessRule to the security settings.
dirSecurity.AddAccessRule(new FileSystemAccessRule(
account,
rights,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));
// Set the new access settings.
dirInfo.SetAccessControl(dirSecurity);
greetings