Generate a .mht file programmatically

Does anyone know how to generate a .mht file programmatically in C #, with embedded images in it? The fact is that I realized that .mht files are capable of embedding images in them, and this embedded image moves along with the entire file (mht) when its location changes. This file can also be viewed in different browsers, including IE 6.

I was asked to try Data Url Scheme technology. But this did not work, because other browsers do not support it. e.g. IE 6.

+8
c # mhtml
source share
4 answers

This was possibly and definitely done by other people - related materials and libraries / source code:

+5
source share

On Windows, you can do this directly using the CDO.Message COM component, which provides the IMessage interface
I don't know the details of importing COM objects in C #, so I will give you a quick example in the C-like syntax:

IMsgObj = CreateObject("CDO.Message") // create the object IMsgObj.CreateMHTMLBody("http://www.example.com/") // convert the URL to MHTML IMsgObj.GetStream().SaveToFile("output.mht") // save it to a file 

CLSID of components CDO.Message {CD000001-8B95-11D1-82DB-00C04FB1625D}

Keep in mind that this component is designed to generate e-mail messages (the file extension is .eml, not .mht), which means that JavaScript files are not included. Otherwise, they are roughly equivalent.

+5
source share

I would start with RFC 2557 so that I have some basic understanding of what I was working with. Then find the code / libraries that relate to this.

As far as I know, there are no BCL classes for working with MHTML.

+1
source share

MSDN has an excellent article (June 2011) on how to create an MHT file using both CDO and System.Net.Mail. C # source code is fully included. I would use this higher version of VB.Net or Google Code.

+1
source share

All Articles