[英]How to load mht from stream/string into a WebBrowser control?
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. 如果我使用Navigate
方法,WebBrowser控件正确加载任何mht
文件,但是当我使用DocumentText
或DocumentStream
属性时, mht
文件的源显示就像我在记事本中打开文件一样。
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. 有些人建议我应该通过实现IPersistMoniker
com接口来欺骗IE,等等。 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? 我仍然觉得他们应该是一个更直接的解决方案(除了首先保存在临时文件中),任何想法?
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. 祝你好运,如果有答案,我也想知道。
in vb.net we've used 在vb.net中我们使用过
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. 问题是IE似乎只接受它。
var uri = new Uri(String.Format("file:///{0}", Path.GetFullPath(source)));
wbMain.Navigate(uri);
where source - path to your .mht file 其中source - .mht文件的路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.