.Net adding directory security with Directory.CreateDirectory()

Quick post on how to set security permissions on a directory in C#.

  const string yourDirectory = @"c:\directory to create\";
  
  var securityRules = new DirectorySecurity();
  
  securityRules.AddAccessRule(
               new FileSystemAccessRule(@"yourdomain\identity", FileSystemRights.FullControl, AccessControlType.Allow)
               );
    
  Directory.CreateDirectory(yourDirectory, securityRules);

Leave a Reply

Your email address will not be published. Required fields are marked *