开发者

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

开发者 https://www.devze.com 2023-02-07 19:03 出处:网络
I\'m u开发者_运维知识库sing Microsoft Visual Studio 2005 and I am able to load a web page using

I'm u开发者_运维知识库sing 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)


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消