The really simplest way is to get a handle on the HTML tag, and then use it's outerHTML method. This will will any doctype information that might be present, but 99% of the time, it should be good enough.
dim oColl as mshtml.IHTMLElementCollection dim oHTML as mshtml.IHTMLElement dim sPageSource as string
oColl = doc.getElementsByTagName("HTML") if not oColl is nothing andalso oColl.length > 0 then oHTML = oColl.item(0) sPageSource = oHTML.outerHTML end if
There's actually many different ways to get a handle on the top HTML tag, but all are prone to the occasional error depending of the quality of the original html source. i've found this way to be the most reliable to cover all breaking cases. I've also had situations where the length of the collection returned in the request for all HTML tag elements to be greater than 1 - which is definitely illegal, but has actually happened, so sometimes even relying on the first HTML tag is not enough.
There's a few different interfaces you can play with. IHTMLDocument, IHTMLDocument2, IHTMLDocument3, IHTMLDocument4, IHTMLDocument5....have a read up on them, they're pretty powerful.
Another way you could do it to get all the source is to loop through the documents child nodes and concatenate a big string. something like:
dim oBuilder as new system.text.stringbuilder dim oDoc3 as mshtml.IHTMLDocument3 = directcast(doc, mshtml.IHTMLDocument3) For each oElement as mshtml.IHTMLElement in oDoc3.childnodes oBuilder.append(oElement.outerHTML) end for
dim sPageSource as string = oBuilder.ToString
Hope that helps you in the right direction, --Geoff