【发布时间】:2009-01-08 18:28:56
【问题描述】:
我有以下代码:
if (System.IO.File.Exists(htmlLocation))
{
vEarthBrowser.ObjectForScripting = this;
vEarthBrowser.Url = new Uri(htmlLocation);
}
else
{
throw new Exception("HTML file not found!");
}
htmlLocation定义为:
private string htmlLocation = "VirtualEarth.html"
据推测,我从中获得此项目的项目处于正常工作状态,但我没有更改任何代码。如果我运行它,新的 Uri() 行会给我一个错误,“无效的 URI:无法确定 URI 的格式。”
文件存在(通过成功通过 If 中的 Exists() 方法表明)。当您希望 WebBrowser 控件在默认应用程序目录中加载 HTML 文件时,在 WebBrowser 控件上引用 URL 的正确方法是什么?
编辑:
我应该澄清一下,这是一个 winforms 项目,而不是一个 web 项目。
【问题讨论】:
-
试试
new Uri(htmlLocation,UriKind.Relative) -
试过这个...得到一个例外,“导航到相对 URL 不成功。”