Create directory with full control to all users

I need to create a directory with full control to all users. Can anyone show me the code to do that?

http://msdn.microsoft.com/en-us/library/9h4z99zb.aspx

TIA
LVL 22
ThomasianAsked:
Who is Participating?
 
Carlos VillegasConnect With a Mentor Full Stack .NET DeveloperCommented:
Hello, try this:
System.Security.AccessControl.DirectorySecurity dirSecurity = new System.Security.AccessControl.DirectorySecurity();
dirSecurity.AddAccessRule(
    new System.Security.AccessControl.FileSystemAccessRule("Everyone",
    System.Security.AccessControl.FileSystemRights.FullControl,
    System.Security.AccessControl.InheritanceFlags.ContainerInherit | System.Security.AccessControl.InheritanceFlags.ObjectInherit,
    System.Security.AccessControl.PropagationFlags.None,
    System.Security.AccessControl.AccessControlType.Allow)
);
// Create the new folder with the custom ACL.
System.IO.Directory.CreateDirectory(@"C:\Temp\MyNewDir", dirSecurity);

Open in new window

0
 
Chad SmithSoftware EngineerCommented:

string path = @"C:\test";
    DirectorySecurity ds = Directory.GetAccessControl(path);
    ds.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));
    Directory.SetAccessControl(path, ds);

Open in new window

0
 
ThomasianAuthor Commented:
When I checked the permission of the folder created, it has "Special Permissions" checked instead of "Full Control".

Any ideas?
0
 
ThomasianAuthor Commented:
Perfect! Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.