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


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