Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1976
  • Last Modified:

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
0
Thomasian
Asked:
Thomasian
  • 2
1 Solution
 
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
 
Carlos VillegasFull 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
 
ThomasianAuthor Commented:
Perfect! Thanks!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now