0
我正在为使用Windows IoT运行在Raspberry Pi上的应用程序编写代码。 我通过Visual Studio 2017上的远程进行开发。C#UWP下载到AppData中:拒绝访问
我必须通过REST下载.zip文件并将其保存到AppData文件夹中。 但我得到这个异常:如果我改变downloadpath成比AppData的另一个文件夹
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.
下载工作正常。
这是我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);
}
});
更好,如果你写:使用(var fileStream = response3.GetResponseStream()){...}。 – PrisonMike