/// <summary> /// This extension method for FileStream sets the security descriptors for the file using a FileSecurity instance. /// </summary> /// <param name="fileStream">An object that represents the file to apply security changes to.</param> /// <param name="fileSecurity">An object that determines the access control and audit security for the file.</param> /// <exception cref="ArgumentNullException"><paramref name="fileStream" /> or <paramref name="fileSecurity" /> is <see langword="null" />.</exception> /// <exception cref="ObjectDisposedException">The file stream is closed.</exception> public static void SetAccessControl(this FileStream fileStream, FileSecurity fileSecurity) { if (fileStream == null) { throw new ArgumentNullException(nameof(fileStream)); } if (fileSecurity == null) { throw new ArgumentNullException(nameof(fileSecurity)); } SafeFileHandle handle = fileStream.SafeFileHandle; if (handle.IsClosed) { throw new ObjectDisposedException(null, SR.ObjectDisposed_FileClosed); } fileSecurity.Persist(handle, fileStream.Name); }
[System.Security.SecuritySafeCritical] // auto-generated public void SetAccessControl(FileSecurity fileSecurity) { if (fileSecurity == null) throw new ArgumentNullException("fileSecurity"); Contract.EndContractBlock(); if (_handle.IsClosed) __Error.FileNotOpen(); fileSecurity.Persist(_handle, _fileName); }