MSHTML + WebRequest

VitaliySDrozd

New member
Joined
Mar 7, 2004
Messages
3
Hi! I need to load html from WebRequest into MSHTML parser.

WebRequest wReq = WebRequest.Create("http://www.mysite.com/myhtml.html");

WebResponse wResp = req.GetResponse();
System.IO.Stream rStream = resp.GetResponseStream();

MSHTML has only IPersistStreamInit and IPersistMoniker inplementations..
how can I load data from this stream into MSHTML?
 
Code:
/// <summary>
/// Creates a HTMLDocument object from a url.
/// </summary>
/// <param name="url">The url to retrieve.</param>
/// <param name="filename">The local filepath of the retrieved url.</param>
/// <returns>The HTMLDocument of the url.</returns>
/// <remarks>Make sure the filename is deleted when no longer needed.</remarks>
HTMLDocumentClass RetrivePage(string url, out string filename)
{
	//download the page
	using(WebClient client = new WebClient())
	{
		filename = Path.GetTempFileName();
		client.DownloadFile(url, filename);
	}
	HTMLDocumentClass mshtmlDoc = new HTMLDocumentClass();
	//load the html document
	try
	{
		System.Runtime.InteropServices.UCOMIPersistFile pf = (System.Runtime.InteropServices.UCOMIPersistFile) mshtmlDoc;
		pf.Load(filename, 0);
		while(mshtmlDoc.body == null)
			System.Windows.Forms.Application.DoEvents();
		while(mshtmlDoc.readyState != "complete")
			System.Windows.Forms.Application.DoEvents();
	}
	catch(Exception e)
	{
		mshtmlDoc.close();
		throw e;
	}
	return mshtmlDoc;
}
 
Last edited by a moderator:
Thank You!

This way assumes NOT async document loading...
I need to load document from the Stream!
Of course, i can save my stream in file... and then load it in MSHTML..
but this is not desirable coding :(
The only way, I think, is to load data using IPersistStreamInit!
but I have no idea how.
 
Back
Top