[英]C# UWP Download into AppData: Access Denied
I'm writing code for an app which runs on a Raspberry Pi with Windows IoT. 我正在为在具有Windows IoT的Raspberry Pi上运行的应用程序编写代码。 I am developing via Remote on Visual Studio 2017. 我正在通过Visual Studio 2017上的Remote开发。
I have to download a .zip file via REST and save it into the AppData-Folder. 我必须通过REST下载.zip文件并将其保存到AppData-Folder中。 But I am getting this Exception: 但是我得到这个异常:
Exception thrown: 'System.UnauthorizedAccessException' in System.IO.FileSystem.dll
Exception thrown: 'System.UnauthorizedAccessException' in System.Private.CoreLib.ni.dll
Access to the path 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\f6e0d540-943b-4fd7-9d4e-1572ca85cec2VS.Debug_ARM.knhelfen\htmls5000\myZipDownload.zip' is denied.
The download works fine if I change the downloadpath into another folder than AppData. 如果将下载路径更改为AppData以外的其他文件夹,则下载工作正常。
This is my downloadmethod: 这是我的下载方法:
Uri uri = new Uri(this.url);
HttpWebRequest getRequest = (HttpWebRequest)HttpWebRequest.Create(uri);
getRequest.Method = this.method;
getRequest.Headers["Authorization"] = "Bearer " + (this.bearerToken);
response3 = await getRequest.GetResponseAsync() as HttpWebResponse;
Stream fileStream = response3.GetResponseStream();
//Download .zip file to downloadPath
await Task.Run(() =>
{
Task.Yield();
using (var path = File.Create(downloadPath + "/myZipDownload.zip"))
{
fileStream.CopyTo(path);
}
});
You can Set folder permissions for UWP apps . 您可以为UWP应用程序设置文件夹权限 。
And try to use CreateFile2 API to the folder. 并尝试对文件夹使用CreateFile2 API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.