Importing a local HTML file/code into a WebBrowser

拜拜、爱过 提交于 2019-12-06 05:28:36

The @ thing is for C#; you don't need it for VB.NET because VB.NET has a different (read: better :-)) escaping system for strings. So, remove the @ before the string, and also get rid of the ; after your lines, which is also C#.

The problem is that, since you're using a WebBrowser, you need a file:/// URL. There are a couple things you can do, the most simple of which is probably to point your WebBrowser to about:blank and put the file in directly, like so:

WebBrowser1.Document.Write(IO.File.ReadAllText("index.html"))

For example. You could also get the file's absolute path, and use that:

WebBrowser1.Navigate("file:///" & IO.Path.GetFullPath(".\index.html"))

I fully agree with the answer given by Minitech. I was making an HTML code tester and wrote this code and it worked.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim sb As New System.Text.StringBuilder
    sb.AppendLine(RichTextBox1.Text)
    IO.File.WriteAllText("htmltester.html", sb.ToString())
    WebBrowser1.Navigate("file:///" & IO.Path.GetFullPath(".\htmltester.html"))
End Sub
End Class

This code worked for my program and i want to tell you that please remove those '@' and ';'.

Another option I found that works, don't have to create a file.

WebBrowser1.DocumentText = strHTML WebBrowser1.Update()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!