简体   繁体   中英

Writing to file giving unauthorized access in c#

FileStream fs = new FileStream("C:\\Users\\admin\\Documents\\test1.rtf", FileMode.Open, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("Hello World");
sw.Dispose();
fs.Dispose();

This code is giving an unauthorized access error even though I declared the <rescap:Capability Name="broadFileSystemAccess"/> in the manifest and allowed the app those permissions in privacy setting in Windows 10. Any help is appreciated.

The problem is that you don't have used the Windows Storage namespace APIs. If you read the document File access permissions , you would know this point.

This capability( broadFileSystemAccess ) works for APIs in the Windows.Storage namespace.

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