简体   繁体   English

写入文件以在C#中提供未经授权的访问

[英]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. 即使我在<rescap:Capability Name="broadFileSystemAccess"/>声明了<rescap:Capability Name="broadFileSystemAccess"/> ,并允许应用程序在Windows 10的隐私设置中具有这些权限,此代码仍给出了未经授权的访问错误。

The problem is that you don't have used the Windows Storage namespace APIs. 问题是您没有使用Windows Storage名称空间API。 If you read the document File access permissions , you would know this point. 如果您阅读了文件文件访问权限文档,您将了解这一点。

This capability( broadFileSystemAccess ) works for APIs in the Windows.Storage namespace. 此功能( broadFileSystemAccess )适用于Windows.Storage命名空间中的API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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