Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

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

Your help would be greatly appreciated.
0
Comment
Question by:AngryC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
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 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

705 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