我正在使用C#编写Winform应用程序。当我试图创建一个文本文件时,我在谷歌上搜索到错误"客户端没有所需的权限",这与用户的权限有关。简单地说,我不允许在我选择的路径中创建文件,该路径是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));
从SpecialFolder枚举的msdnoc
用作文档通用存储库的目录。这成员相当于MyDocuments。
如果你只需要创建一个临时文件,你可以调用:
Path.GetTempFilename();
哪个Creates a uniquely named, zero-byte temporary file on disk and returns the full path of that file
,请参阅msdn文档