简体   繁体   中英

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, but 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?

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");

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM