Directory.CreateDirectory 对路径的访问被拒绝?

Mur*_*sli 6 c# permissions access-control create-directory

在此输入图像描述

我有服务器客户端应用程序,它是一个文件管理器,
我的问题是当我进入需要访问控制(如系统文件夹)的文件夹时,它变为只读,但我需要移动/删除或创建新文件夹,我该如何获得许可这样做吗?

这是我在服务器端创建新文件夹的方法

public void NewFolder(string path)
    {
        try
        {
            string name = @"\New Folder";
            string current = name;
            int i = 0;
            while (Directory.Exists(path + current))
            {
                i++;
                current = String.Format("{0} {1}", name, i);
            }
            Directory.CreateDirectory(path + current);
            Explore(path); //this line is to refresh the items in the client side after creating the new folder
        }
        catch (Exception e)
        {
            sendInfo(e.Message, "error");
        }
    }
Run Code Online (Sandbox Code Playgroud)

Han*_*ant 4

驱动器上通常存在即使具有管理员权限的用户也无法访问的目录。名为“HDDRecovery”的目录很可能会带来这样的麻烦。当然,它包含可以帮助用户从磁盘故障中恢复的敏感数据。另一个适合此类别的目录是“c:\system volume information”,它包含还原点数据。

管理员可以像这样更改文件夹的权限。但这当然不能解决真正的问题,也不是明智之举。您的用户不能也不应该这样做。请务必编写处理此类权限问题的代码,只需捕获 IOExeption 即可。永远不要显示设置了“隐藏”或“系统”属性的目录,以免用户遇到麻烦。它们是“别惹我”的属性。