Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-02-10
6
Medium Priority
?
363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Praveen Kumar
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:Praveen Kumar
ID: 34868522
Sorry:

string html = System.IO.File.ReadAllText("your html file path");
webBrowser1.DocumentText = html
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Accepted Solution

by:
chandra_darbha earned 2000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Progress
Introduction to Processes

604 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