views:

276

answers:

1

I have an webbrowser control on my form. I am able display 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 ??

+1  A: 

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.

Hans Passant