C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限

//给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);

C#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限

上一篇:在Linux上运行C#


下一篇:TCP的三次握手与四次挥手