In my vb.net program, I am using a webbrowser to show the user an HTML preview. I was previously hitting a server to grab the HTML, then returning on an asynchronous thread
That worked for me:
webBrowser.Navigate("about:blank");
webBrowser.Document?.Write(htmlString);
I found the following and it worked!
webBrowser.Navigate("about:blank");
webBrowser.Document.OpenNew(false);
webBrowser.Document.Write(html);
webBrowser.Refresh();
please refer to this answer c# filenotfoundexception on webbrowser?
Just spotted this in some of our old code.
_webBrowser.DocumentText = builder.WriteToString( ... );
Application.DoEvents();
Apparently a DoEvents also kicks the browser into rendering
While Application.DoEvents()
fix it in a WinForms project, it was irrelevant in a WPF project.
I finally got it to work by using webBrowser.Write( htmlContent )
(instead of webBrowser.DocumentText = htmlContent
).
This always works
using mshtml;
private IHTMLDocument2 Document
{
get
{
if (Browser.Document != null)
{
return Browser.Document.DomDocument as IHTMLDocument2;
}
return null;
}
}
if (Document == null)
{
Browser.DocumentText = Contents;
}
else
{
Document.body.innerHTML = Contents;
}