我正在尝试更改.NET Core中文件的权限。但是,似乎FileInfo不再具有任何SetAccessControl
。
// Create a new FileInfo object.
FileInfo fInfo = new FileInfo(FileName);
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = fInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType));
// Set the new access settings.
fInfo.SetAccessControl(fSecurity);
目标只是向文件的当前所有者添加执行权(不是Windows或Unix特定功能)。>>
有关如何在.NET Core上执行此操作的任何线索?
我正在尝试更改.NET Core中文件的权限。但是,似乎FileInfo不再具有任何SetAccessControl。 //创建一个新的FileInfo对象。 FileInfo fInfo =新FileInfo(...
FileSecurity
类现在是.NET Core System.IO.FileSystem.AccessControl程序包的一部分。不再有File.GetAccessControl
方法,因此您将需要自己实例化FileSecurity
实例。
这时有两种扩展方法:GetAccessControl
和SetAccessControl
,用于FileInfo
,DirectoryInfo
等。>
因此您可以使用var ac = new FileInfo(path).GetAccessControl()
,此表达式在.NET Framework和.Net Core中均有效。但是您仍然需要dotnet add package System.IO.FileSystem.AccessControl
。