I'm currently moving to the WebView2 control from the .NET WebBrowser control and have run into an issue opening a HTML file that has an anchor in the path.
For example with the current WebBrowser control, I can open a local HTML file like so: "c:\test.html#1111" where the 1111 is the anchor. The browser control opens the file and goes to the anchor. However, with the webview2 control, I get a file not found error. If I leave off the anchor part of it, it opens fine.
Can someone please point me in the right direction to open up the file and go to the anchor? Thanks!
The problem is that #1111
is treated as part of the file name - and that file doesn't exist.
You should be able to do:
UriBuilder uriBuilder = new UriBuilder(@"c:\test.html")
{
Fragment = "1111"
};
webView21.Source = uriBuilder.Uri;