Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# .NET How can I show an image on WebBrowser control?

How can I show an image on a webbrowser control in C#/.NET? I'm doing something like

webBrowser1.DocumentText = "<html><head></head><body><img src=imagelocationURL.png/></body></html>"

but the image doesn't appear. What am I doing wrong?

like image 368
dmessf Avatar asked May 31 '10 00:05

dmessf


1 Answers

I would guess one of two things: either that, as codeka points out, you are missing the quotes (single or double) around imagelocationURL.png and the tag is not rendering; or else you need to examine the location of your .png file. For sure, add the quotes:

webBrowser1.DocumentText = "<html><head></head><body><img src='imagelocationURL.png'/></body></html>" 

Then, try hardcoding the path to your .png file and see if that works:

webBrowser1.DocumentText = "<html><head></head><body><img src='C:/Temp/imagelocationURL.png'/></body></html>"

If the hardcoded path works, then you just need to play around with your code to pull out the equivalent of the hardcoded path.

like image 112
Steve Elmer Avatar answered Sep 24 '22 13:09

Steve Elmer