我将设置文件的完全访问权限 ( fileName
)。我找到了一个代码示例:
var security = IO.File.GetAccessControl(fileName);
security.AddAccessRule(new Security.AccessControl.FileSystemAccessRule(
new SecurityIdentifier(WellKnownSidType.WorldSid, null),
Security.AccessControl.FileSystemRights.FullControl,
Security.AccessControl.AccessControlType.Allow));
IO.File.SetAccessControl(fileName, security);
它运行良好,但我不明白为什么我应该将它传递filename
给该SetAccessControl
方法(我已经在第一行提供了它)?我对代码进行了更改,发现这也有效:
var security = IO.File.GetAccessControl(anotherFileName);
security.AddAccessRule(new Security.AccessControl.FileSystemAccessRule(
new SecurityIdentifier(WellKnownSidType.WorldSid, null),
Security.AccessControl.FileSystemRights.FullControl,
Security.AccessControl.AccessControlType.Allow));
IO.File.SetAccessControl(fileName, security);
那么anotherFileName
这里有什么用呢?