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 ??

6 Years
Discussion Span
Last Post by hankas


I think that when you use DocumentStream the webBrowser does not know what the root folder is thus only fully qualified paths will work. Try this:

webBrowser.Url = new Uri(@"..\HtmlPages\supportHtml.html");

Hope this helps.


I dont have any problem with html files. My control is able to display it. but there are some images in it which are not shown if i give relative path.
I also made an installer for my app with absolute path for image but image are not displayed. :(
I have to set src attribute of img tag within html files. So cant use application.startup to get root path.


I understand that this is an old thread and probably the original poster no longer needs the solution. However, I post my solution here in case if someone else has the same problem.

  1. When you add your html files and images into the Visual Studio, open their properties, be sure to select your build action to "None" and select always copy to output folder or copy if newer.
  2. Then in your code, to make your browser navigate to the html file,
    //replace yourfile and yourfolder with your file and folder's names
    Uri uri = new Uri("pack://siteoforigin:,,,/yourfile.html"); //or pack://siteoforigin:,,,/yourfolder/yourfile.html

In this case, you are putting your html files and stuffs outside your assembly. The good thing about this design is that you do not need to rebuild your assembly every time you change your html file, and any images or css files used by your html files will still be rendered correctly.

Edited by hankas: n/a

This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.