How to set MACL from one directory to another? [Ravi Krishnaswamy]

How to set MACL from one directory to another? [Ravi Krishnaswamy]

  • Comments 2

A correct way to do this will be as follows:

 

// Get DirectorySecurity from source directory

DirectorySecurity dsSrc = Directory.GetAccessControl(srcPath, AccessControlSections.Access);

 

// Transfer ACL security descriptor

byte[] sdBinary = dsSrc.GetSecurityDescriptorBinaryForm();

DirectorySecurity dsDst = new DirectorySecurity();

dsDst.SetSecurityDescriptorBinaryForm(sdBinary, AccessControlSections.Access);

 

// Set new DirectorySecurity to destination directory

Directory.SetAccessControl(dstPath, dsDst); //Destination

 

 

Page 1 of 1 (2 items)