【问题标题】:IOException: "A required privilege is not held by the client." best way to overcome?IOException:“客户未拥有所需的特权。”最好的克服方法?
【发布时间】:2013-08-26 15:54:44
【问题描述】:

我正在使用 C# 编写 Winform 应用程序。在尝试创建文本文件时,我收到错误“客户端未持有所需的权限”。我用谷歌搜索过,与用户的权限有关。简单来说就是不允许我在我选择的路径下创建文件,也就是C:/

试过这个解决方案:http://www.technitips.com/2010/06/a-required-privilege-is-not-held-by-the-client-windows-7/,只工作过一次。克服这种错误的最佳方法是什么?我应该更改整个 Window 的安全设置吗?或者把路径改到不需要管理员权限的地方?

【问题讨论】:

  • 您也可以尝试以“以管理员身份运行”模式打开 Visual Studio,以避免在许多情况下出现此错误。

标签: c# security


【解决方案1】:

也许可以通过调用GetFolderPath找到更好的文件夹路径

Environment.GetFolderPath(Environment.SpecialFolder.Personal));

来自SpecialFolder enum的msdndoc

用作文档公共存储库的目录。这个 member 相当于 MyDocuments。

如果你只需要创建一个临时文件你可以调用:

Path.GetTempFilename();

其中Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file,见msdn doc

【讨论】:

    猜你喜欢
    • 2012-03-28
    • 2015-09-08
    • 1970-01-01
    • 2020-10-05
    • 2019-11-04
    • 2023-03-16
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多