FileSecurity Constructor (String, AccessControlSections)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the FileSecurity class from a specified file using the specified values of the AccessControlSections enumeration.

Namespace:   System.Security.AccessControl
Assembly:  mscorlib (in mscorlib.dll)

public FileSecurity(
	string fileName,
	AccessControlSections includeSections


Type: System.String

The location of a file to create a FileSecurity object from.

Type: System.Security.AccessControl.AccessControlSections

One of the AccessControlSections values that specifies the type of access control list (ACL) information to retrieve.

Exception Condition

The fileName parameter is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.


The specified path is invalid, (for example, it is on an unmapped drive).


The file specified in the fileName parameter was not found.


An I/O error occurred while opening the file.


path is in an invalid format.


The fileName parameter is null.


The current operating system is not Microsoft Windows 2000 or later.


The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.


The current system account does not have administrative privileges.


The file could not be found.


The fileName parameter specified a file that is read-only.


This operation is not supported on the current platform.


The fileName parameter specified a directory.


The caller does not have the required permission.

This constructor retrieves the access control information for the specified file and then creates a FileSecurity object that encapsulates that information. You can then inspect, add, or delete the access control information for the specified file.

You can add access or audit rules to the FileSecurity object using the AddAccessRule method. You can remove access or audit rules using the RemoveAccessRule method.

To persist new or changed access or audit rules to a file, use the SetAccessControl or SetAccessControl method. To retrieve access or audit rules from an existing file, use the GetAccessControl or GetAccessControl method.

Notes to Callers:

The FileSecurity constructor requires the current account to have administrative privileges. To create a new instance of the FileSecurity class for a specific file using an account that does not have administrative privileges, use the FileStream.GetAccessControl method.


for permission to access the file specified by the name parameter. Associated enumerations: NoAccess , View

Security action: Demand

.NET Framework
Available since 2.0
Return to top