Link to home
Start Free TrialLog in
Avatar of r3nder
r3nderFlag for United States of America

asked on

displaying a web page on page load in a windows form C#

I have a web page called home.htm in the root directory of the project file for my windows form. I am using a web browser control. I would like it to display the htm page on
Page_Load
{

}
I tried webrowser1.Navigate(new uri = "file://home.htm");
But I get an error - does anyone know how to do this
Avatar of SterlingMcClung
SterlingMcClung

You will have to use the full path to the file in the uri.  You should be able to use My.Application.Info.DirectoryPath to get the directory of your application.
webbrowser1.Navigate(new Uri(String.Format("http://{1}/file.htm",My.Application.Info.DirectoryPath))

Open in new window

You can do something like:

string html = System.IO.File.ReadToEnd("your html file path");
webBrowser1.DocumentText = html

Sorry:

string html = System.IO.File.ReadAllText("your html file path");
webBrowser1.DocumentText = html
ASKER CERTIFIED SOLUTION
Avatar of chandra_darbha
chandra_darbha

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello:
If you exe and html are in the same directory, use this code. It works.

Best regards.
Uri pageUri= new Uri(Path.GetFullPath("MyHtmlPage.htm"));

Open in new window

Avatar of r3nder

ASKER

perfect
Thank you........and the only one that worked