我正在使用C#编写Winform应用程序.在尝试创建文本文件时,我收到错误"客户端未保留所需的权限".我用Google搜索,与用户的权限有关.简单地说,我不允许在我选择的路径中创建一个文件,即C:/
试过这个解决方案:http://www.technitips.com/2010/06/a-required-privilege-is-not-held-by-the-client-windows-7/,只工作过一次.克服这种错误的最佳方法是什么?我应该更改整个Window的安全设置吗?或者将路径更改为不需要管理员权限的地方?
也许通过调用GetFolderPath找到更好的文件夹路径
Environment.GetFolderPath(Environment.SpecialFolder.Personal));
Run Code Online (Sandbox Code Playgroud)
从msdndoc for SpecialFolder枚举
用作文档公共存储库的目录.该成员相当于MyDocuments.
如果您只需要创建一个临时文件,您可以调用:
Path.GetTempFilename();
Run Code Online (Sandbox Code Playgroud)
其中Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file,请参阅msdn doc