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

只愿长相守 提交于 2019-11-28 05:17:45

问题


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?


回答1:


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.




回答2:


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.




回答3:


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

where source - path to your .mht file



来源:https://stackoverflow.com/questions/4705139/how-to-load-mht-from-stream-string-into-a-webbrowser-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!