[英]Download file and save it in isolated storage
我的Windows 8 / RT應用程序中有以下代碼:
public static async Task<StorageFile> SaveAsync(Uri fileUri, StorageFolder folder, string fileName)
{
try
{
var file = await folder.CreateFileAsync(fileName);
var downloader = new BackgroundDownloader();
var download = downloader.CreateDownload(fileUri, file); // here Exeption is fired
var res = await download.StartAsync();
return file;
}
catch (Exception e)
{
Debug.WriteLine(ex.Message);
}
return null;
}
消息: Access denied
注意:
file
-這是正確的StorageFile
( ContentType=image/jpg
)
fileUri
正確的圖像uri
folder
-這是正確的存儲文件夾。
我錯過了什么?
調用代碼時folder
的值是多少? 您可能需要在Package.appxmanifest中向相應的文件夾(例如,Pictures文件夾,Documents文件夾)添加功能。
默認情況下,Modern UI應用程序的沙盒性質意味着它僅可以對其自己的本地文件夾進行顯式訪問(請像“隔離存儲”一樣考慮它)。 為了訪問其他位置,清單文件必須聲明它需要訪問其他位置。 但是,可用位置非常有限。
但是,如果使用“保存文件選擇器”,則可以訪問更大范圍的位置來保存文件。
我發現很少的錯誤:
我忘了,那個fileUri
是本地服務器的Uri。 只需添加嵌套屬性即可解決已解決的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.