2

I have a WinForm on a local computer in VB

I have a WebBrowser control.

I have a WebView control.,

I can load a local file into the WebBroswer with : Form1.WebBrowser1.Navigate(App.Path & "/ip.html")

I can load a URL into WebView with :

MainForm.WebView1.NavigateToString= New Uri(String.Format("http://www.website.com/myPage.html"))

I can load a html as a string into WebView with :

MainForm.WebView1.Source = New Uri(String.Format("<html><h1>My Text Goes Here</h1></html>"))

How do I load a local html file into WebView?

These doesn't work :

    Form1.WebView1.Navigate(App.Path & "/ip.html")
    Form1.WebView1.Navigate("file:///" & App.Path & "/MyPage.html")
    Form1.WebView1.Source(App.Path & "/MyPage.html")
    Form1.WebView1.Source("file:///" & App.Path & "/MyPage.html")
Form1.WebView1.NavigateToLocal("file:///" & App.Path & "/MyPage.html")
Form1.WebView1.NavigateToLocal(App.Path & "/MyPage.html")
  • I would have thought that `Form1.WebView1.Source = New Uri($"file:///{Application.StartupPath}/MyPage.html")` should work. `Source` is a property so you set it; you don't call it. It's type `Uri` so you should be assigning a `Uri` object to it. The source is a file so it should be a file URI. Your app is WinForms so you use `Application.StartupPath` to get the folder the EXE was run from. Simple logic. – jmcilhinney Jan 09 '19 at 01:35
  • [WebView.NavigateToString](https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.webview.navigatetostring) – Jimi Jan 09 '19 at 01:41
  • Did you ever get this resolved? If so, can you please post the code because I'm having the same issue trying to display a local HTML file. – GamerDev Jan 24 '20 at 20:26
  • Does this answer your question? [Is it possible to make WebView control to read local html files?](https://stackoverflow.com/questions/55516387/is-it-possible-to-make-webview-control-to-read-local-html-files) – schlebe May 17 '20 at 05:27

0 Answers0