码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-01-06 19:35:35      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

//给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#修改文件或文件夹的权限,为指定用户、用户组添加完全控制权限

标签:

原文地址:http://www.cnblogs.com/pingming/p/4206653.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!