C# Modify the permissions of files or folders and add full control permissions to specified users and user groups. Specific code introduction

黄舟
Release: 2017-03-13 11:41:30
Original
1895 people have browsed it

C#Modify the permissions of files or folders and add specific codes for full control permissions for specified users and user groupsIntroduction

//给Excel文件添加"Everyone,Users"用户组的完全控制权限  
FileInfo fi = new FileInfo(excelPath);  
System.Security.AccessControl.FileSecurity fileSecurity = fi.GetAccessControl();  
fileSecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));  
fileSecurity.AddAccessRule(new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow));  
fi.SetAccessControl(fileSecurity);  
  
//给Excel文件所在目录添加"Everyone,Users"用户组的完全控制权限  
DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(excelPath));  
System.Security.AccessControl.DirectorySecurity dirSecurity = di.GetAccessControl();  
dirSecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));  
dirSecurity.AddAccessRule(new FileSystemAccessRule("Users", FileSystemRights.FullControl, AccessControlType.Allow));  
di.SetAccessControl(dirSecurity);
Copy after login

The above is the detailed content of C# Modify the permissions of files or folders and add full control permissions to specified users and user groups. Specific code introduction. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!