Solved

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

Posted on 2011-02-10
6
355 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:r3nder
6 Comments
 
LVL 7

Expert Comment

by:SterlingMcClung
ID: 34868488
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

0
 
LVL 12

Expert Comment

by:Mamtha1982
ID: 34868498
You can do something like:

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

0
 
LVL 12

Expert Comment

by:Mamtha1982
ID: 34868522
Sorry:

string html = System.IO.File.ReadAllText("your html file path");
webBrowser1.DocumentText = html
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 3

Accepted Solution

by:
chandra_darbha earned 500 total points
ID: 34868567
The code attached will work for what you are trying to do. But, in general, at the end of development your application (i.e the exe ) should have the Htm file exactly 2 levels above it.

 
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate(string.Format("file:///{0}/../../file.html", System.IO.Path.GetDirectoryName(Application.ExecutablePath)));
        }
    }

Open in new window


Ideal case is to place the htm in the same location as the exe or in any standard location which you are sure is the deployment pattern
0
 
LVL 8

Expert Comment

by:cubaman_24
ID: 34870148
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

0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 34871368
perfect
Thank you........and the only one that worked
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now