Solved

How can I display a .mht file on a webBrwoser control?

Posted on 2006-07-14
14
1,549 Views
Last Modified: 2012-08-30
The title says it!

Your help would be greatly appreciated.
0
Comment
Question by:AngryC
  • 5
  • 4
  • 4
14 Comments
 
LVL 7

Expert Comment

by:whatsit2002
ID: 17113402
Ok, I've got to ask: did you mean .htm?

I'm wondering if the issue is the file or how to display it.

Thanks.

Jason
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17114242
I believe that the title is correct--.mht and not .htm.  mht is a single-file type that has a structure that doesn't require external files, like images.  What happens if you navigate to the .mht file?

Bob
0
 
LVL 7

Expert Comment

by:whatsit2002
ID: 17114571
Thanks Bob.

AngryC,

You should be able to set the .Url property of the WebBrowser control to the uri (translate: path) of the file. So, if for example, the .MHT file (test.mht) was on your desktop, the code would be:

webBrowser1.Url = new Uri(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\test.mht");

Thanks.

Jason
0
 

Author Comment

by:AngryC
ID: 17114702
Thanks for your follow-ups.

I acually know it's possible to load a file if it's saved. But what I'm trying to do is to load the mht file from resource as follow:

webBrowser1.Document.Body.InnerHtml = global::WindowsApplication1.Resource1.MyMhtFileName;

What I am getting is a page that looks like it was opened with notepad not with IE!!!

Please help.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17114835
1) >>opened with notepad
What does that mean?  Are you losing the HTML formatting?

2) What is WindowsApplication1.Resource1.MyMhtFileName returning?

3) What encoding are you using?

Bob

0
 

Author Comment

by:AngryC
ID: 17114851
1) Yes. I'm losing the HTML formatting.

2) The file source (string).

3) I'm not specifying any but I'm sure it's not a matter of encoding. I think I should change the MIME type the webBrowser control. But I don't know how...
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 17114888
1) This is header from an .mht file:

From: <Saved by Microsoft Internet Explorer 5>
Subject: Online Account Services
Date: Mon, 19 Dec 2005 08:41:51 -0500
MIME-Version: 1.0
Content-Type: multipart/related;
      type="text/html";
      boundary="----=_NextPart_000_0000_01C60478.0E7B3520"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180

This is a multi-part message in MIME format.

2) How did you embed the value for MyMhtFileName?

Bob
0
 

Author Comment

by:AngryC
ID: 17114917
There's no problem with my mht file, it's working when I'm doing this:

webBrowser1.Url = new Uri(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\test.mht");

I'm also getting the exact content file the file from the resource without any problem, the problem is how can I send it to the webBrowser control?
0
 
LVL 7

Expert Comment

by:whatsit2002
ID: 17115669
Is saving the contents back to a file an option? If so, you could write the resource back to a file in the temp folder and then give the browser control its path. Just a thought.

Jason
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17115684
I didn't say that there was a problem with .mht.  It looks like you are trying to extract the file as an embedded resource from the assembly, so I am trying to figure out how it is getting mangled.

Bob
0
 

Author Comment

by:AngryC
ID: 17116306
I want to load it directly from the resource. I don't want to save the file on desk before using it.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17129317
Yes, but when you are loading it from the resource, then it doesn't look correct, so I am trying to figure out why.

Bob
0
 
LVL 7

Accepted Solution

by:
whatsit2002 earned 50 total points
ID: 17134304
It looks to me like you're out of luck for now. Until Microsoft lets us set the MIME type of the document, you may have to do something like this:

            //get the bytes of the MHT file from the resources of this application
            byte[] mht = global::MyNamespace.Properties.Resources.Testing;
            string filename = Environment.GetEnvironmentVariable("TEMP") + @"\tmp.mht";
            //save the bytes back to a file
            File.WriteAllBytes(filename, mht);
            //load the file in the browser
            webBrowser1.Url = new Uri(filename);

I cannot come up with a way to tell the web browser control what MIME type it is suppose to be using to open the memory stream. Bob, have you had any luck?

Thanks.
Jason
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now