开发者

Problem with image path of html files viewed by webbrowser control

I have an webbrowser control on my form. I am able disp开发者_如何转开发lay html files in that control. But my page contains some images if i give absolute path to it then images are displayed. But if i give relative path then images are not shown in the pages.

I have HtmlPages folder located at bin folder.

And i am assigning

FileStream source = new FileStream(@"..\HtmlPages\supportHtml.html", FileMode.Open, FileAccess.Read);
webBrowser.DocumentStream = source;

If i assign D:\myapp\bin\HtmlPages\file.png then there is no problem. My images are stored in same folder. If i open html files with webbrowser then images are displayed.

What is the correct path to set ??


Relative paths are relative to WebBrowser.Url. Which, when you load the HTML directly, either through DocumentStream or DocumentText is about:blank. That's not going to help WB find the file, you must use an absolute path. Tinkering with the Url property is not an option.

Consider using Html Agility Pack to tinker with the file content before assigning it to the DocumentText property. Use Path.GetFullPath() to translate relative paths.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜