How can I show an image on a webbrow开发者_JAVA技巧ser 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?
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.
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));
精彩评论