FileStream.SetAccessControl(FileSecurity) FileStream.SetAccessControl(FileSecurity) FileStream.SetAccessControl(FileSecurity) Method


FileSecurity 对象所描述的访问控制列表 (ACL) 项应用于当前 FileStream 对象所描述的文件。Applies access control list (ACL) entries described by a FileSecurity object to the file described by the current FileStream object.

 void SetAccessControl(System::Security::AccessControl::FileSecurity ^ fileSecurity);
public void SetAccessControl (System.Security.AccessControl.FileSecurity fileSecurity);
member this.SetAccessControl : System.Security.AccessControl.FileSecurity -> unit


FileSecurity FileSecurity FileSecurity

描述要应用于当前文件的 ACL 项的对象。An object that describes an ACL entry to apply to the current file.


fileSecurity 参数为 nullThe fileSecurity parameter is null.

未能找到或修改该文件。The file could not be found or modified.

当前进程不具有打开该文件的权限。The current process does not have access to open the file.


虽然类和SetAccessControl可用于现有File.SetAccessControl文件, 但请考虑使用方法, 因为它更易于使用。 FileStreamWhile the FileStream class and SetAccessControl can be used on an existing file, consider using the File.SetAccessControl method as it is easier to use.

SetAccessControl方法将访问控制列表 (ACL) 项应用于表示 noninherited ACL 列表的文件。The SetAccessControl method applies access control list (ACL) entries to a file that represents the noninherited ACL list.


为该fileSecurity参数指定的 acl 将替换该文件的现有 acl。The ACL specified for the fileSecurity parameter replaces the existing ACL for the file. 若要为新用户添加权限, 请使用GetAccessControl方法获取现有 ACL, 对其进行修改, 然后使用SetAccessControl将其应用回文件。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.

ACL 描述对给定文件具有或没有特定操作权限的个人和/或组。An ACL describes individuals and/or groups who have, or do not have, rights to specific actions on the given file. 有关详细信息,请参阅如何:添加或移除访问控制列表项For more information, see How to: Add or Remove Access Control List Entries.