Change a File's ACL to Allow Full Access for Everyone

冷暖自知 提交于 2019-12-06 14:39:44

Indeed, there are API's available for this. You may want to have a look at the File.SetAccessControl method in the System.IO namespace.

// Read the current ACL details for the file
var fileSecurity = File.GetAccessControl(fileName);

// Create a new rule set, based on "Everyone"
var fileAccessRule = new FileSystemAccessRule(new NTAccount("", "Everyone"),
      FileSystemRights.FullControl, 
      AccessControlType.Allow);

// Append the new rule set to the file
fileSecurity.AddAccessRule(fileAccessRule);

// And persist it to the filesystem
File.SetAccessControl(fileName, fileSecurity);

The forementioned article has tons of great things to play with, regarding the ACL.

You can use FileInfo.GetAccessControl and File.SetAccessControl methods

check the sample code given in MSDN link for File.SetAccessControl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!