我正在为使用Windows IoT的Raspberry Pi上运行的应用编写代码。 我是在Visual Studio 2017上通过Remote开发的。
我必须通过REST下载.zip文件并将其保存到AppData-Folder中。 但是我得到了这个例外:
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.
如果我将下载路径更改为除AppData之外的其他文件夹,则下载工作正常。
这是我的下载方法:
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);
}
});
答案 0 :(得分:1)