Export (0) Print
Expand All

FileSecurity Constructor (String, AccessControlSections)

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
)

Parameters

fileName
Type: System.String

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

includeSections
Type: System.Security.AccessControl.AccessControlSections

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

ExceptionCondition
ArgumentException

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

DirectoryNotFoundException

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

FileNotFoundException

The file specified in the fileName parameter was not found.

IOException

An I/O error occurred while opening the file.

NotSupportedException

path is in an invalid format.

SEHException

The fileName parameter is null.

PlatformNotSupportedException

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

PathTooLongException

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.

PrivilegeNotHeldException

The current system account does not have administrative privileges.

SystemException

The file could not be found.

UnauthorizedAccessException

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

-or-

This operation is not supported on the current platform.

-or-

The fileName parameter specified a directory.

-or-

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.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

  • FileIOPermission 

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

    Security action: Demand

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft