Issue to set folder permission
DirectorySecurity directorySecurity =
Directory.GetAccessControl(@"C:\MyFolder");
SecurityIdentifier fullControl = new SecurityIdentifier(
WellKnownSidType.WorldSid, null);
directorySecurity.AddAccessRule(
new FileSystemAccessRule(
fullControl,
FileSystemRights.Modify | FileSystemRights.Synchronize,
InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
PropagationFlags.None,
AccessControlType.Allow));
Directory.SetAccessControl(@"C:\MyFolder", directorySecurity);
With above code I tried to set folder permission. It throwing following
error this access control list is not in canonical form and therefore
cannot be modified. But if set folder permission using command like below.
C:\>cacls c:\MyFolder /t /e /g Everyone:f
Now the expecting scenario is working well. But I want to achieve this
dynamically.
No comments:
Post a Comment