P.H.
P.H.

Reputation: 481

How do I resolve images in a HTML file loaded by WebBrowser control

I'm using Microsoft Visual Studio 2005 and I am able to load a web page using

string exePath = Application.ExecutablePath ;
int n =  exePath.LastIndexOf("\\");
// the web page & image is in the same directory as the executable
string filename = exePath.Substring(0, n)+ "\\switchboard.htm"; 
webBrowser1.DocumentStream = new FileStream(filename, FileMode.Open);

The text of the web page loads ok, but this

<img src="cardpack1.jpg" height="200" alt="card">

results in a broken image.

The image file is in the same directory as the html file. I'm not even sure what to google. All of the questions I've found appear to be doing fancier things like resolving images from resource bundles and trying to dynamically display/not display images.

So, any advice would be appreciated (even if it's just ... google for x, y, z)

Upvotes: 2

Views: 845

Answers (1)

Conrad Frix
Conrad Frix

Reputation: 52645

Why not just use the WebBrowser.Navigate Method instead. A URI can be a local file. Its also a good idea to use the Path methods to create your string.

     string exePath = Application.ExecutablePath;
     string htmPath = Path.Combine( Path.GetDirectoryName(exePath) , "switchboard.htm");

     webBrowser1.Navigate(htmPath);

Upvotes: 2

Related Questions