----- Original Message ----- From: "Steven Livingstone" <[EMAIL PROTECTED]> > Well that wasn't as simple as it may sound. The reason is discussed in > the posting [1] from Praveen Kosuri @ Microsoft. An extract... > > "What you have found is the way to write to the HTMLDOcument from a .NET > application. If you use VB6 to do this,internally, VB6 virtual machine > automatically initializes MSHTML.HTMLDocument (with > "<html><body></body></html>"). After initializing, the Length of the > object > works correctly. However, in .NET world (VB.NET or C# for that matter), > you > need to explicitly initialize the object before calling any methods. And > how to do that? It is done using methods of IPersistStreamInit interface > (like you did ). COM Interop Services provides wrappers for any > interfaces > (checkout members of System.Runtime.InteropServices). However, it does > not > provide a wrapper for this interface. You will need to implement the > interface yourself." > > The *only* way I could get this to work (and there may be others) is as > follows: > > IHTMLDocument2 doc = new HTMLDocumentClass(); > doc.write("<html>nothing to see here!</html>"); //this can be any HTML > doc.close(); //close and the doc is set to readyState "complete" (if > you don't it stays at "loading")
When I was loading HTML from a string variable, I did something similar, but instead of explicitly creating a IHTMLDocument2 object, I used the AxWebBrowser's navigate method to load about:blank, and then retrieved it's document object, which I then casted to a IHTMLDocument2 (IIRC) object, which I could use to insert html. This worked fine, and it sounds like your method skips a few steps, which might be nice. > while (doc.readyState != "complete") > System.Threading.Thread.Sleep(50); I found that if you add a call to Application.DoEvents(), this loop will execute fewer times. In regards to scripting, do you know if there is a way to disable scripting, so any javascript never runs? I would hate to be loading a page and have a bunch of popup windows appear :) Thanks, Erick You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.