How to load mht from a stream / line into a WebBrowser control?

The WebBrowser controller loads any file correctly mhtif I use the method Navigate, but when I use the DocumentTextor properties DocumentStream, the source of the mht file is displayed as if I opened the file in notepad.

If I write a stream to a temporary file, then go to it, it works correctly, but I do not want to do this.

This problem seems common, but I did not find a working solution for it. Some people suggest that I cheat IE by implementing the IPersistMonikercom, ..., etc. interface . I tried with this a bit, but unfortunately I got the same result. Maybe I did something wrong. I still feel this should be a simpler solution (besides saving to a temporary file), any idea?

+3
source share
3 answers

I remember that several years ago I ran into the same problem, and although I was looking for a solution, I did not find it. In the end, I went for a temporary approach. I wish you good luck, and if there is an answer, I would also like to know.

+2
source

in vb.net we 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()

The only problem is that IE seems to be accepting it.

+2
var uri = new Uri(String.Format("file:///{0}", Path.GetFullPath(source)));
wbMain.Navigate(uri);

where source is the path to your .mht file

+1
source

Source: https://habr.com/ru/post/1785719/


All Articles