[英]C# GetFileAsync Permission Denied
In the C# app I am writing, I created a blank text file called "WriteLines.txt" in my Solution Explorer using the Add New Item feature. 在我编写的C#应用程序中,我使用“添加新项”功能在“解决方案资源管理器”中创建了一个空白文本文件“ WriteLines.txt”。
However, When I try to modify this text file and set its content equal to a string I named output using the following lines of code, I get the Permission Denied exception on the " FileIO.WriteLineAsync code (E_ACCESSDENIED)
": 但是,当我尝试修改此文本文件并将其内容设置为使用以下代码行命名为输出的字符串时,在“
FileIO.WriteLineAsync code (E_ACCESSDENIED)
”上得到“权限被拒绝”异常:
var file1 = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("WriteLines.txt");
await FileIO.WriteTextAsync(file1, output);
The "WriteLines.txt" file is not read-only, I already checked its properties. “ WriteLines.txt”文件不是只读的,我已经检查了它的属性。
Does anyone spot the problem? 有人发现问题了吗?
The other option is to make sure that you run VS as an administrator. 另一个选择是确保以管理员身份运行VS。 So when you run VS right click the exe and select run as administrator.
因此,在运行VS时,右键单击exe,然后选择以管理员身份运行。 That should elevate permissions.
那应该提升权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.