Reputation: 1013
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?
Upvotes: 5
Views: 9399
Reputation: 860
If you can live with the content being in a file instead of passing the whole html content, you can easily achieve it by doing this:
if (File.Exists(filetoopen))
this.webBrowser1.Url = new Uri(String.Format(filetoopen));
Upvotes: 1
Reputation: 939
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.
Upvotes: 4