4

The WebBrowser control loads properly any mht file if I use the Navigate method, but when I use the DocumentText or DocumentStream properties, the source of the mht file is displayed as if I opened the file in notepad.

If I write the stream to a temp file then Navigate to it, it works properly, but I don't want to do it this way.

This issue seems common, but I didn't find a working solution for it. Some people suggest I should fool IE by implementing IPersistMoniker com interface, ...etc. I have tried with this a little bit, but unfortunately I got the same result. May be I have done something wrong. I still feel their should be a more straightforward solution (other than saving in a temp file first), any idea?

Community
  • 1
  • 1
Sameh Deabes
  • 2,960
  • 25
  • 30

3 Answers3

2

I remember I was facing the same issue a few years ago and although I searched for a solution then I did not find any. In the end, I went for the temp-file approach. I wish you good luck, and if there's an answer I would like to know too.

mikabytes
  • 1,818
  • 2
  • 18
  • 30
  • Although I stated in my question that I don't want the temp-file approach, but I ended up that I should use it! I succeeded to fool WebBrowser control by implementing a simple web server with HttpListener http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx but finally I found the WebBrowser itself saved the file in the "Temporary Internet Files"! For simplicity, I will save the file myself and delete it after loading completed. – Sameh Deabes Jan 17 '11 at 12:58
  • Haha :) Well, there will be many points of failure. I hope you're not planning on doing anything important. Otherwise, congrats :) – mikabytes Jan 19 '11 at 20:59
1

in vb.net we've used

Response.ContentType = "message/rfc822" 
Dim ByteDocBlob() As Byte = cwWebUtil.ConvertLocalFileToByteArray(FilePath, True)
Dim HTMLText As String = System.Text.Encoding.UTF8.GetString(ByteDocBlob)
Response.Write(HTMLText)
Response.End()

Problem is only IE seems to accept it.

Greg
  • 19
  • 1
  • Response is only valid in a web application context. The OP was speaking about a control used in WinForms not the web. – Bill Jul 13 '18 at 20:40
1
var uri = new Uri(String.Format("file:///{0}", Path.GetFullPath(source)));
wbMain.Navigate(uri);

where source - path to your .mht file

Maxim
  • 51
  • 4