简体   繁体   中英

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.

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) ":

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.

Does anyone spot the problem?

The other option is to make sure that you run VS as an administrator. So when you run VS right click the exe and select run as administrator. That should elevate permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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