Getting content with images into the Web Browser control without temporary files
For a client server application, I'd like to display content with a web browser control with images without writing temporary files to the disk.
I've tried using mht files via documentstream and documenttext, bu开发者_运维百科t the web browser control isn't smart enough to recognize mht files.
I would use data URI images, however most computers this will be installed on use IE6 or 7.
Are there any other options for this?
I'm not sure if it would help at all, but maybe you could try using a different browser control such as WebKit .NET?
That way you could be certain about its features (mht, data URI, etc.)
I know how much of a pain the Microsoft web browser component can be.
Load the Web site, but add a no-cache
header. Something like as follows:
WebBrowser web = new WebBrowser();
web.Navigate("http://yourURL.com", string.Empty, null, "Pragma: no-cache");
You can register your own protocol for images
If you want to go through the MHTML route, you need to call the document's IPersistStreamInit/IPersistMoniker by yourself. If I remember correctly the WinForm WebBrowser control assumes the input stream to be UTF-8, and does not provide a IMoniker implementation to let you specify the base url of the document.
Note there are some limitations on IE's MHTML support, such as not all protocols are supported, site limits on MHTML attachments, lack of MHTML support on mobile phones and early versions of Windows for PC without Outlooks Express or Word, etc.
精彩评论