c#webbrowser编码导航到本地的html(c# webbrowser coding to navigate local to html)

编程入门 行业动态 更新时间:2024-10-25 07:27:26
c#webbrowser编码导航到本地的html(c# webbrowser coding to navigate local to html)

我正在尝试将本地html位置地址放在我的C#应用​​程序中的Web浏览器中但总是失败。 我现在正在使用调试模式,因此html文件已经复制到我的Debug文件夹中,因为我总是将copy复制到copy to output选项。 以下是我的代码:

string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); string filePath = Path.Combine(appPath, "index.html"); webBrowser1.Navigate(new System.Uri(@"file://"+ filePath));

总是会出现这种错误:

An unhandled exception of type 'System.UriFormatException' occurred in System.dll

知道出了什么问题吗?

I'm trying to put a local html location address to the web browser in my C# application but always failed. I'm using debug mode now so the html files had already copied into my Debug folder because i put copy always in the copy to output option. Below is my code:

string appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); string filePath = Path.Combine(appPath, "index.html"); webBrowser1.Navigate(new System.Uri(@"file://"+ filePath));

There always this error coming out using that way:

An unhandled exception of type 'System.UriFormatException' occurred in System.dll

Any idea what went wrong?

最满意答案

它有点不清楚,但试试这个。 希望这可能有所帮助。

webBrowser1.Navigate(new Uri(@"your File Name"))

要么

webBrowser1.Navigate(new Uri(AppDomain.CurrentDomain.BaseDirectory == "\\File Name")

编辑:可能是这导致错误,

webBrowser1.Navigate(new System.Uri("@" filePath + "file://"));

Its a bit unclear but try this out. Hope this may help.

webBrowser1.Navigate(new Uri(@"your File Name"))

Or

webBrowser1.Navigate(new Uri(AppDomain.CurrentDomain.BaseDirectory == "\\File Name")

Edit: May be this causing error,

webBrowser1.Navigate(new System.Uri("@" filePath + "file://"));

更多推荐

本文发布于:2023-07-28 01:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1298242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:html   webbrowser   coding   local   navigate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!