File.SetAccessControl(String, FileSecurity) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Applies access control list (ACL) entries described by a FileSecurity object to the specified file.
public:
static void SetAccessControl(System::String ^ path, System::Security::AccessControl::FileSecurity ^ fileSecurity);
public static void SetAccessControl (string path, System.Security.AccessControl.FileSecurity fileSecurity);
static member SetAccessControl : string * System.Security.AccessControl.FileSecurity -> unit
Public Shared Sub SetAccessControl (path As String, fileSecurity As FileSecurity)
- path
- String
A file to add or remove access control list (ACL) entries from.
- fileSecurity
- FileSecurity
A FileSecurity object that describes an ACL entry to apply to the file described by the path
parameter.
An I/O error occurred while opening the file.
The path
parameter is null
.
The file could not be found.
The path
parameter specified a file that is read-only.
-or-
This operation is not supported on the current platform.
-or-
The path
parameter specified a directory.
-or-
The caller does not have the required permission.
The fileSecurity
parameter is null
.
The SetAccessControl method applies access control list (ACL) entries to a file that represents the noninherited ACL list.
Awas
The ACL specified for the fileSecurity
parameter replaces the existing ACL for the file. To add permissions for a new user, use the GetAccessControl method to obtain the existing ACL, modify it, and then use SetAccessControl to apply it back to the file.
An ACL describes individuals and groups who have, or don't have, rights to specific actions on the given file. For more information, see How to: Add or Remove Access Control List Entries.
The SetAccessControl method persists only FileSecurity objects that have been modified after object creation. If a FileSecurity object has not been modified, it will not be persisted to a file. Therefore, it's not possible to retrieve a FileSecurity object from one file and reapply the same object to another file.
To copy ACL information from one file to another:
Use the GetAccessControl method to retrieve the FileSecurity object from the source file.
Create a new FileSecurity object for the destination file.
Use the GetSecurityDescriptorBinaryForm or GetSecurityDescriptorSddlForm method of the source FileSecurity object to retrieve the ACL information.
Use the SetSecurityDescriptorBinaryForm or SetSecurityDescriptorSddlForm method to copy the information retrieved in step 3 to the destination FileSecurity object.
Set the destination FileSecurity object to the destination file using the SetAccessControl method.
In NTFS environments, ReadAttributes and ReadExtendedAttributes are granted to the user if the user has ListDirectory rights on the parent folder. To deny ReadAttributes and ReadExtendedAttributes, deny ListDirectory on the parent directory.
Produk | Versi |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET maklum balas
.NET ialah projek sumber terbuka. Pilih pautan untuk memberikan maklum balas: