tags:

views:

911

answers:

6

Or if any body knows of an alternative control that does?

It would be handy to serve up content to the WebBrowser control that has embedded images & other resources from a database without having a dependency on these resources being hosted on a webserver or to create temporary files on the local file system.

Mhtml supports this but doesn't seem to work in a WebBrowser control when using the DocumentText property?

+1  A: 

Seems to be working for me.

example:

this.webBrowser1.Url = new System.Uri(@"C:\TempFiles\MyTest.mht");

what in particular is not working correctly?

sbeskur
A: 

I was referring to the situation where you are setting the DocumentText property. If I'm loading content from a database, I don't want to have to create temporary files on the local file system.

LyphTEC
+1  A: 

I don't think that what you are trying to achieve is possible using the DocumentText property. MHTML is a document archive format and although it is stored as text with binary data such as images etc. encoded to base64 strings, there does not seem to be any intelligence built into the DocumentText property of the webbrowser control to read this file format. Looking into this property with Reflector you will see that a different mechanism is used to handle this as opposed to the Url property which invokes the "guts" of the webbrowser control via the underlying COM object.

It also doesn't appear that you can accomplish this by writing to the DocumentStream property either.

sbeskur
A: 

Thanks for your insight.

I've basically been using the temporary file approach and think that it would be more elegant if the DocumentText property supported this, however it may not be possible as you say.

I remember stumbling across a solution once where someone had wrote a lot of COM interop hackery code to make it work but for the life of me & can't find the reference to it anymore.

LyphTEC
A: 

You could create a standard compiled resource assembly (unmanaged, not sure about managed) that contains all of your images, then link into the library like so:

<img src="res://yourdll.dll/image.jpg" />

A really good article on this and a good implementation can be found here: http://www.delphidabbler.com/articles?article=10

Personally I just used the vb6 compiler for resources only and link into them, but most non-managed compilers will do the same thing.

Tom Anderson