Targeted
Navigation:

Technology All The Way
Iodid Weblogs
 

Standard
Navigation:

Home
FAQ
Search
Table of Contents

Email:

TryandGuess
-at-
iodid.com

Search this weblog:


Visitor Count:
Money Grubbing:

Amazon Honor System Click Here to Pay Learn More

Terms of Use

October 21, 2003

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:\WINDOWS\SYSTEM32\cdosys.dll
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("http://www.fanms.com/", 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("http://www.iodid.com", CDO.CdoMHTMLFlags.cdoSuppressNone, "", "")

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

Posted by tmichael at October 21, 2003 03:44 PM
Comments

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

Posted by: Kele on November 13, 2003 08:51 PM

Unfortunately I don't. Sorry.

Posted by: tmichael on November 14, 2003 08:09 AM

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.

/Sondre

Posted by: Sondre Bjellås on January 10, 2004 11:50 AM
Post a comment