开发者

How to set full control to a directory

开发者 https://www.devze.com 2023-03-04 03:04 出处:网络
I am using the following code to set full control DirectorySecurity myDirectorySecurity = source.GetAccessControl();

I am using the following code to set full control

DirectorySecurity myDirectorySecurity = source.GetAccessControl();
string User = "Srinivass\\Admin";
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(
                        User,
                        FileSystemRights.Modify,
                        InheritanceFlags.ObjectInherit,
                        PropagationFlags.In开发者_运维技巧heritOnly,
                        AccessControlType.Allow)
                    );

source.SetAccessControl(myDirectorySecurity);

But it is giving special permissions to this folder only. I want to give full controll permissions to all subfolders.

Please anyone can help me.


Try changing PropagationFlags parameter to PropagationFlags.None.

Your access rule should look like:

 new FileSystemAccessRule( 
          User, 
          FileSystemRights.FullControl,
          InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
          PropagationFlags.None,
          AccessControlType.Allow 
  );

Then, check the Security tab in Windows Explorer, and you should see the folder (and any newly created objects going forward) having Full Control.

0

精彩评论

暂无评论...
验证码 换一张
取 消