【发布时间】:2017-03-24 23:57:09
【问题描述】:
我需要下载并保存文件。我使用此代码(使用 Xam.Plugins.DownloadManager 和 PCLStorage 库):
public static string DownloadNewXml(string LinkToFile, string PathFile)
{
var downloadManager = CrossDownloadManager.Current;
CrossDownloadManager.Current.PathNameForDownloadedFile = new System.Func<IDownloadFile, string>(file => {
return PathFile;
});
try
{
var file = downloadManager.CreateDownloadFile(LinkToFile);
downloadManager.Start(file);
return "ok";
}
catch(Exception e)
{
return e.ToString() ;
}
}
PathFile 是:FileSystem.Current.LocalStorage.Path + "file.xml"; 此代码在 Android 和 UWP 上引发异常 - 我无法将文件写入此路径 (FileSystem.Current.LocalStorage.Path)。所以我有一个问题。如何在所有平台(Android、UWP、iOS)上为我的应用程序获取可写文件夹的路径?请帮忙。
【问题讨论】:
标签: xamarin xamarin.forms