簡體   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