Monday, September 3, 2007

Directory Security and Access Rules

 

using System.Security.AccessControl;
 
    FileSystemAccessRule faRule;
    FileSystemRights fsrRights;
 
    fsrRights = FileSystemRights.FullControl;
    faRule = new FileSystemAccessRule(
        new NTAccount("DOMAIN\\user"), 
        fsrRights, 
        InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, 
        PropagationFlags.InheritOnly, AccessControlType.Allow
    );
 
    //security.AddAccessRule(faRule);
    //File.SetAccessControl(txtFile.Text, security);
 
 
    DirectorySecurity dirsec = Directory.GetAccessControl(@"\\server\sub$\folder");
    dirsec.AddAccessRule(faRule);
    Directory.SetAccessControl(@"\\server\sub$\folder", dirsec);

 

The best explanation (MSDN)

Example1

Example2

ACL Propagation rules

No comments:

Post a Comment