views:

34

answers:

1

Hello,

I found a method for copying ntfs permissions information from one existing folder to a newly created one - I'm not sure if it's doing the work it should do. Maybe one can have a look at the method and give some comments:

private static void CopySecurityInformation(String source, String dest)
{
    FileSecurity fileSecurity = File.GetAccessControl(
        source,
        AccessControlSections.All);
    FileAttributes fileAttributes = File.GetAttributes(source);
    File.SetAccessControl(dest, fileSecurity);
    File.SetAttributes(dest, fileAttributes);
}

Thanks for your help, Daniel

+1  A: 

It does slightly more than just copying the NTFS permissions. It also copies the attributes of the file. I'm not quite certain whether it copies inherited permissions, though, but run it once and you should be able to find out.

Note that copying permissions on and of itself requires special permissions (administrators have these, of course), be sure the process running this method has the required permissions to query, view and set permissions on those objects.

Abel
Well - copying permissions _and_ attributes was exactly the behaviour I wanted to achieve. - sorry I didn't tell you before... ;-)And yes, the application ensures that the administrator account is used.
dhh