【发布时间】:2019-03-14 13:23:40
【问题描述】:
我正在尝试打开一个多页 HTML 网页(即 test.html、test.css 和 test.js),该网页已动态下载(因此无法使用资产)并存储在应用程序内部存储(Xamarin. Essentials.FileSystem.AppDataDirectory)。
我尝试使用的网址如下:
file:///data/user/0/com.test/files/HTML/Test.html
但是我只是找不到文件。
var filesToDownload = new string[] { "http://myserver/test/test.html", "http://myserver/test/test.css" };
var directory = System.IO.Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, "HTML");
if (System.IO.Directory.Exists(directory))
{
System.IO.Directory.Delete(directory, true);
}
System.IO.Directory.CreateDirectory(directory);
using (var wc = new System.Net.WebClient())
{
foreach (var f in filesToDownload)
{
wc.DownloadFile(f, System.IO.Path.Combine(directory, System.IO.Path.GetFileName(f)));
}
}
var source = new UrlWebViewSource
{
Url = System.IO.Path.Combine("file://" + directory, "Test.html")
};
WebView1.Source = source;
【问题讨论】:
-
System.IO.Path.Combine("file://" + directory, "Test.html") 解析到什么?您是否为 html 文件设置了有效的文件 Url?
-
file:///data/user/0/com.test/files/HTML/Test.html
-
经过一番谷歌搜索后,我发现 WebView 使用单独的 AppData 文件夹运行,无法访问主 AppData 文件夹。
-
我已经发布了您的问题的答案,请尝试一下。
标签: c# xamarin.forms xamarin.forms.webview