Total Pageviews

Tuesday, May 21, 2013

How to give permissions to a folder pro-grammatically using C# in Windows

Below are the code which gives full control to a folder programmatically


 var dInfo = new DirectoryInfo(@"C:\\MyFolder");
            DirectorySecurity dSecurity = dInfo.GetAccessControl();
            dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
            dInfo.SetAccessControl(dSecurity);


Enjoy reading

No comments:

Post a Comment