System.Security.AccessControl.FileSystemSecurity.AddAccessRule Method

Adds the specified access control list (ACL) permission to the current file or directory.

Syntax

public void AddAccessRule (FileSystemAccessRule rule)

Parameters

rule
A System.Security.AccessControl.FileSystemAccessRule object that represents an access control list (ACL) permission to add to a file or directory.

Remarks

The FileSystemSecurity.AddAccessRule(FileSystemAccessRule) method adds a new rule to the list of rules contained within a System.Security.AccessControl.FileSystemSecurity object.

If an access control list (ACL) already exists for the specified rule, the FileSystemSecurity.AddAccessRule(FileSystemAccessRule) method will still add the rule, with one exception: a System.Security.AccessControl.FileSystemAccessRule object created using the AccessControlType.Deny enumeration value supersedes an object created using the AccessControlType.Allow enumeration value.

To persist new or changed ACL information to a file, use the System.IO.File.SetAccessControl(string, FileSecurity) or System.IO.FileInfo.SetAccessControl(FileSecurity) method. To persist new or changed ACL information to a directory, use the System.IO.Directory.SetAccessControl(string, DirectorySecurity) or System.IO.FileInfo.SetAccessControl(FileSecurity) method.

To retrieve ACL information from a file, use the erload:System.IO.File.GetAccessControl or erload:System.IO.FileInfo.GetAccessControl method. To retrieve ACL information from a directory, use the erload:System.IO.Directory.GetAccessControl or erload:System.IO.DirectoryInfo.GetAccessControl method.

When you add an access rule without setting the FileSystemRights.Synchronize flag, the FileSystemRights.Synchronize flag will be automatically added to your rule. If you remove the rule later without specifying the FileSystemRights.Synchronize flag, the flag will automatically be removed.

Requirements

Namespace: System.Security.AccessControl
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0