0
Windows IoTのラズベリーパイで実行されるアプリケーションのコードを作成しています。 Visual Studio 2017でリモートから開発中です。C#UWP AppDataにダウンロード:アクセスが拒否されました
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より別のフォルダにdownloadpathを変更した場合、ダウンロードが正常に動作します。あなたはSet folder permissions for UWP appsでき
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);
}
});
あなたが書いた方が良いでしょう:using(var fileStream = response3.GetResponseStream()){...}。 – PrisonMike