Question about save html file as mht file

A

Andy Chen

Hi,

I found a vbs file on the internet, it can do this job very well:
------------------
'MakeMHT.vbs

Const adSaveCreateNotExist = 1
Const adSaveCreateOverWrite = 2
Const adTypeBinary = 1 'Binary data
Const adTypeText = 2 '(Default) Text data

URL = "http://ideas.live.com/mainpage.aspx"
DiskFile = "C:\test.mht"

Set objMessage = CreateObject("CDO.Message")
objMessage.CreateMHTMLBody URL
SaveToFile objMessage, DiskFile

Sub SaveToFile(Msg, Fn)
Dim Strm, Dsk
Set Strm = CreateObject("ADODB.Stream")
Strm.Type = adTypeText
Strm.Charset = "UTF-8"
Strm.Open
Set Dsk = Msg.DataSource
Dsk.SaveToObject Strm, "_Stream"
Strm.SaveToFile Fn, adSaveCreateOverWrite
End Sub
------------------
But I want to do it in my C# application, the following is my code:

public static void WBSaveAsMHT(ref AxSHDocVw.AxWebBrowser webBrowser, string
fileName)
{
CDO.Message msg = null;
CDO.Configuration config = null;
ADODB.Stream stream = null;
string url = null;
if(webBrowser == null)
{
throw new Exception("The webbrowser control is null.");
}
try
{
url = webBrowser.LocationURL;
msg = new CDO.MessageClass();
config = new CDO.ConfigurationClass();

msg.Configuration = config;
msg.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");

stream = new ADODB.StreamClass();
stream = msg.GetStream();
stream.SaveToFile(fileName,
ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
}
catch(Exception ex){...}
}

My code can download and create MHT file, but when I open the MHT file in
IE, the images cannot be displayed. I have opened the MHT file in notepad
and found the images were actually downloaded and achieved. I don't know
what's wrong in my c# code.

Any help would appreciate!
 

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

Similar Threads


Top