开发者

How to set full control to a directory

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜