Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET: How to make WebBrowser control launch in IE, display HTML, out of process?
    primarykey
    data
    text
    <p>i want to create a WebBrowser control, give it the HTML to display, then make it appear out of process in its own Internet Explorer window.</p> <p>Can it be done?</p> <hr> <ul> <li>yes it has to be out of process</li> <li>i already have a technique that involves writing a temporary file. i want to remove this hack solution</li> </ul> <hr> <p>i have three other questions on stackoverflow running, all working on a tiny segment of making the following code work:</p> <pre><code>public static void SpawnIEWithSource(String szHtml) { IWebBrowser2 ie = (IWebBrowser2)new InternetExplorer(); object mv = System.Reflection.Missing.Value; //special "nothing" value object url = (String)@"about:blank"; ie.Navigate2(ref url, ref mv, ref mv, ref mv, ref mv); mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)ie.Document; doc.Write(szHtml); doc.Close(); ie.Visible = true; } </code></pre> <p><strong>Note:</strong> The above code works fine in native apps.</p> <p>i thought i would cut to the chase, and see if anyone has any other ideas, that don't involve the only way i've been able to figure it out.</p> <hr> <p>The hack solution, that uses a temporary file, is:</p> <pre><code>public static void SpawnIEWithSource(String szHtml) { IWebBrowser2 ie = (IWebBrowser2)new InternetExplorer(); object mv = System.Reflection.Missing.Value; //special "nothing" value object url = (String)@"about:blank"; ie.Navigate2(ref url, ref mv, ref mv, ref mv, ref mv); //Todo: Figure out the .NET equivalent of the following //so that it doesn't have to write a temporary file //IDispatch webDocument = ie.Document; //webDocument.Write(szHtml); //webDocument.Close(); String tempFilename = Path.GetTempFileName(); try { //Rename to .htm, or else ie won't show it as actual HTML String htmlFile = Path.ChangeExtension(tempFilename, "htm"); File.Move(tempFilename, htmlFile); //.NET's version of File.Rename tempFilename = htmlFile; //Write string to file StreamWriter writer = new StreamWriter(tempFilename); writer.Write(szHtml); writer.Close(); url = (String)tempFilename; ie.Navigate2(ref url, ref mv, ref mv, ref mv, ref mv); //If we're going to delete the file, then we have to wait for IE to use it //else we delete it before it uses it while (ie.ReadyState != tagREADYSTATE.READYSTATE_COMPLETE) { System.Threading.Thread.Sleep(10); } } finally { File.Delete(tempFilename); } //Make IE Visible ie.Visible = true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload