我想将一些文件夹权限(设置为只读)更改为 ReadWriteExecute!
我写了这段代码,但是文件夹权限仍然是只读的:
private void ChangePermissions(string folder)
{
string userName = Environment.UserName;
FileSystemAccessRule accessRule = new FileSystemAccessRule(userName, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit
| InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);
DirectoryInfo directoryInfo = new DirectoryInfo(folder);
DirectorySecurity directorySec = directoryInfo.GetAccessControl();
directorySec.AddAccessRule(accessRule);
directoryInfo.SetAccessControl(directorySec);
}
如果我想删除此目录,Directory.Delete(folder, true)
我会收到以下错误消息:
“访问路径‘条目’被拒绝。”
当然,权限仍然是只读的!
这里有什么问题?