[英]File.CreateText - Access Denied
我最近花了一段時間試圖弄清楚讓這個語句起作用需要什么權限:
if (!File.Exists(path))
{
// Create a file to write to.
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
}
我最終擁有“每個人”的“特殊權限”,這應該可以解決問題。 可悲的是它沒有,它實際上可能是一個錯誤?
以下工作:
if (!File.Exists(_logFilePath))
{
using (var fs = File.Create(_logFilePath))
{
using (var sw = new StreamWriter(fs))
{
sw.WriteLine("Hello");
sw.WriteLine("And");
sw.WriteLine("Welcome");
}
}
}
理論上相同(我認為),但我無法讓第一個工作。
我認為路徑變量是錯誤的。 確保您還在路徑中輸入了文件名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.