繁体   English   中英

UnauthorizedAccessException错误

[英]UnauthorizedAccessException Error

资深用户,当我遇到以下错误时,尝试使用System.IO从Visual C#中的控制台应用程序写入文件: UnauthorizedAccessException unhandled (我正在观看的课件中不存在)。 我知道这是一个非常简单的问题,已经在msdn.com上寻找了解决方案,但我所能找到的只是我的问题是安全错误或System.IO错误,与如何解决该问题无关。

这是代码:

string someText = "I want to write this to a text file!";

File.WriteAllText(@"C:\Users\Keagan\Desktop\
    C#projects\UnderstandingNamespaces", someText);

此致K.Roe

我遇到了完全相同的问题。 您有两种解决方案:

第一个:确保您对该文件夹具有完全权限。

Go to folder -> Right click -> Properties -> Security Tab -> Select user -> Edit -> Allow Full Control.

第二种解决方案(最有可能):

string someText = "I want to write this to a text file!";

确保您的someText变量包含扩展名的文件名。 例如: MyFile.txt或类似的东西。 除此之外,请确保您的filePath正确。

我遇到了同样的问题,但是我不知道为什么Visual Studio会抛出这个奇怪的异常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM