Changing permissions on child folders in C#

后端 未结 2 1701
孤城傲影
孤城傲影 2021-01-19 23:54

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

2条回答
  •  孤城傲影
    2021-01-20 00:17

    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

提交回复
热议问题