Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Programmatically display .MHT files inline

Thread Tools

Programmatically display .MHT files inline

srivalli chavali via
Posts: n/a

I have a PDF file and a MHT file.
Following is the code I'm using to read the file and display it INLINE in
the browser.
PageData is a MemoryStream object that contains the file's actual stream of

---------------------------- PDF files ----------------------------
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Type", "application/pdf");
Response.AddHeader("content-disposition", "inline;filename=file.pdf");

---------------------------- MHT files ----------------------------
Response.ContentType = "message/rfc822";
Response.AddHeader("Content-Type", "message/rfc822");
Response.AddHeader("content-disposition", "inline;filename=file.mht");

Using the above code, I can successfully view the PDF files, but NOT MHT
For MHT files, Blank IE window appears and the "View Source" displays the
following HTML.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<META http-equiv=Content-Type content="text/html; charset=windows-
Please note that I can view both PDF and MHT files successfully as
attachments, as opposed to being inline.
i.e., Response.AddHeader("content-disposition",
"attachment;filename=file.mht"); works absolutely fine.

I'm wondering if MHT files can be viewed inline at all. If yes, please let
me know where I'm doing it wrong.

Thanks in advance.


Message posted via
Reply With Quote
DanielSands DanielSands is offline
Junior Member
Join Date: Mar 2010
Posts: 1
Hi Srivalli,

I too had this exact same problem - I'm working on a web-based email client, and wanted to use Window's mht parsing to display the email, rather than having to parse the content myself. My first approach was to simply create the mht file and redirect to it, but obviously this didn't work - and I just got the "File Download" window. Annoying!

Anyway, having browsed various forums online with no joy. I finally managed to create a solution. All be it a rather horrible one, but it works non-the-less, so I thought i'd share my findings with you.

So - the problem here is showing a mht within a browser, and having established that that simply isn't possible, I scratched my head for a while before realizing that the mht file CAN be viewed if opened in a "WebBrowser" component within VB6.

So, if you create a new DLL - and within that DLL have a form with a WebBrowser component on it - you can pass the requested mht file to it, allow windows to do its stuff - and then grab the innerHTML of the WebBrowser and save it to a html file - which can then obviously be displayed inline on a page.

Yes, this isn't an elegant solution, but - it works, and is pretty straight forward to implement. I would post examples of the coding - but I currently have the code amongst other (private) things within my DLL, and as the coding is somewhat straight forward - it shouldn't be difficult for you to implement.

If you need any further information please let me know, otherwise I hope this works for you! And anybody else in the same predicament.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmatically display .MHT files inline =?Utf-8?B?U3JpdmFsbGk=?= ASP .Net 0 05-19-2005 11:40 PM
Programmatically display .MHT files inline srivalli chavali via ASP .Net 0 05-18-2005 09:41 PM
To inline or not to inline? Alvin C++ 7 05-06-2005 03:04 PM
testing for existence of an inline file with Inline::Files Sven Wolf Perl Misc 7 12-03-2004 10:17 PM
inline or not to inline in C++ Abhi C++ 2 07-03-2003 12:07 AM