Saveas MTH file


I want to download and programatically save web pages as mht files. I was having a hard time until I went to IE SaveAS MHTML in C#, where I found the following code:

Make a reference to these two COM objects:
C:\Program Files\Common Files\System\ado\msado15.dll

I don't think neither of these have PIAs (Primary Interop Assembly) so this will generate two typelibs for your project.

The Source:

CDO.MessageClass message = new CDO.MessageClass();
message.CreateMHTMLBody("", CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");

ADODB.Stream stream = message.GetStream();
stream.SaveToFile("fanms.mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite);

Now I just have to change it to VB.

Update: Here is my version of this code in VB:

Dim message As New CDO.MessageClass()
message.CreateMHTMLBody("", CDO.CdoMHTMLFlags.cdoSuppressNone, "", "")

Dim Outstream As ADODB.Stream
Outstream = message.GetStream
Outstream.SaveToFile("c:\test.mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite)


Don't suppose you know how to take a Exchange Post ".eml" file and move/save it to a folder on the Exchange Server?

Unfortunately I don't. Sorry.

Nice to see my code was usefull for you :)
I've recently updated my site, but I've re-added the article with the MHTML part.

In one of my projects we're I used this code, I had an timeline-viewer that generated thumbnails of these MHTML (.mht) archives using interop calls and displayed them after first months, then after dates if the user selected something. This by itself would be a smashing tool, so I might consider doing this as a standalone thing.


About this Entry

This page contains a single entry by tmichael published on October 21, 2003 3:44 PM.

Very Useful Moveable Type Plug-in was the previous entry in this blog.

CDOSYS.dll missing is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.