MHT/MSHTML displaying in the WebBrowser

A

Andy Bates

Hi -

This issue seems to have been kicking around since the dawn of time and no
one appears to have come up with an answer.

In short the MHT/MSHTML provides a method of archiving an HTML page into a
single MIME encoded file that specifies all of the resources for a page in a
single file.

This makes a lot of sense as if you could pass one of these to the
WebBrowser.DocumentStream property then you could display a sensible HTML
document with images/css etc. all being resolved. They could also be stored
in resources or generated on the fly to display an HTML page. All well and
good.

The problem with specifying a document (HTML) to DocumentText or
DocumentStream is that external references on the page cannot easily be
provided (unless someone knows otherwise?). The only method of achieving
this is to write the file out to a temporary directory as disk based files
and then use WebBrowser.Navigate to display it.

The only way to get MHT/MSHTML files displayed correctly also appears to be
to write them to disk and then call WebBrowser.Navigate which seems crazy.
It appears that WebBrowser or MSHTML/SHDocView has the capability to display
them but it doesn't appear to be exposed (unless of course that they do
interally get written to disk?).

This doesn't make sense if you can generate the document in memory. You then
have to write it out to display it.

Various articles seem to state that by implementing the IPersistStreamInit
interface will resolve the problem. I have spent a fair amount of time
implementing the above interface along with IPersistStream/IStorage etc. to
see if they resolve the problem.

None of what I have tried to date has enabled me to display the files
correctly. They get rendered but all of the MIME information is shown on
screen as if it is HTML text and they look shocking.

I just wondered if anyone i) knows a solution to this problem and is willing
to share it, or ii) has any other ideas with regards to how to display them
as I must admit I'm running out of things to try?

Regards

- Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top