The DirectorySecurity class specifies the access rights for a system directory and how access attempts are audited. This class represents access and audit rights as a set of rules. Each access rule is represented by a FileSystemAccessRule object, while each audit rule is represented by a FileSystemAuditRule object.
The DirectorySecurity class is an abstraction of the underlying Microsoft Windows file security system. In this system, each directory has a discretionary access control list (DACL), which controls access to the directory, and a system access control list (SACL), which specifies the access control attempts that are audited. The FileSystemAccessRule and FileSystemAuditRule classes are abstractions of the access control entries (ACEs) that comprise DACLs and SACLs.
The DirectorySecurity class hides many of the details of DACLs and SACLs; you do not have to worry about ACE ordering or null DACLS.
Use the FileSecurity class to retrieve, add, or change the access rules that represent the DACL and SACL of a file.
To persist new or changed access or audit rules to a directory, use the SetAccessControl or SetAccessControl method. To retrieve access or audit rules from an existing directory, use the GetAccessControl or GetAccessControl method.