C#修改文件或文件夾的權(quán)限,為指定用戶、用戶組添加完全控制權(quán)限
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
//給Excel文件添加"Everyone,Users"用戶組的完全控制權(quán)限 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"用戶組的完全控制權(quán)限
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); 該文章在 2018/9/8 15:19:29 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |