• Log in or sign up for an account here: https://www.sythe.org/login

open new form, load a .html file?

hampe-92

Forum Addict
Joined
Jul 10, 2008
Sythe Gold
0
Messages
328
open new form, load a .html file?
Hi
I need some help, I want that when I click a button my form2 with a webbrowser opens, but i want the web browser to open a html file that I have made... how should one go about doing that?
thx in advance!
 
open new form, load a .html file?
Just navigate to the HTML file.

i.e.
Code:
webBrowser1.Navigate(@"C:\index.html");

If you wanted something in the same directory as your browser application,
Code:
webBrowser1.Navigate(Application.StartupPath + @"\index.html");

The '@' simply denotes that it is a path, so escape characters are ignored, and backslashes are used to separate the directories. You can always use forward slash, I guess it depends on your coding habits.
 
open new form, load a .html file?
Backslashes are better since that's what Windows uses, (though it accepts forward slashes for filepaths as well.)
 
open new form, load a .html file?
Just navigate to the HTML file.

i.e.
Code:
webBrowser1.Navigate(@"C:\index.html");

If you wanted something in the same directory as your browser application,
Code:
webBrowser1.Navigate(Application.StartupPath + @"\index.html");

The '@' simply denotes that it is a path, so escape characters are ignored, and backslashes are used to separate the directories. You can always use forward slash, I guess it depends on your coding habits.

So if i have a html file inside my prjoject e.g;
(here is the Solution explorer)
WindowsFormsApplication1
+Properties
+References
+Form1
+Form2
+Folder
> myFile.html
> myFile_LinksToThis.html
Program.cs

and whant that webBrowser1 should navigate to myFile.html
then I should write like this?

public void form1_Load(object sender, System.EventArgs e)
{
webBrowser1.Navigate(Application.StartupPath + @"\Folder\myFile.html");
}


sorry, I haven't got time to test it atm...
and thx very much for your help :)
 
open new form, load a .html file?
I think the WebBrowser control actually has a property called "Url" which you can set, and the browser loads the page at "Url" on startup.
 
open new form, load a .html file?
I think the WebBrowser control actually has a property called "Url" which you can set, and the browser loads the page at "Url" on startup.
yeah that's right, it has a url property, but I have tried to add the path but it doesn't work :/
 
open new form, load a .html file?
ok.. this code works, but I have to have a folder with all the htlm files in at the same place as the .exe file... what I wanted was to have the thml files build in to the exe file... I don't know if that is possible but if someone finds out how to do it please post here or pm me :)

Code:
webBrowser1.Navigate(Application.StartupPath + @"\index.html");
 
open new form, load a .html file?
ok.. this code works, but I have to have a folder with all the htlm files in at the same place as the .exe file... what I wanted was to have the thml files build in to the exe file... I don't know if that is possible but if someone finds out how to do it please post here or pm me :)

Code:
webBrowser1.Navigate(Application.StartupPath + @"\index.html");
You could store the entire HTML file in to a hardcoded string, then create a temporary file from that string and navigate to it.
 
open new form, load a .html file?
You could store the entire HTML file in to a hardcoded string, then create a temporary file from that string and navigate to it.
what do you mean with "Hardcoded string"? what is it, could you please explain a little more?
 
open new form, load a .html file?
What I mean is, create a string, and store the entire HTML file in that string. Any block of text is a string, so just store the HTML file in there, and create a temporary one upon execution.
 
open new form, load a .html file?
hmm.. I'm not sure that I get it right... Do you mean that I should store the whole html code in a string?? and if that's right, how do I create a temp html file from that?
 
open new form, load a .html file?
You would use file I/O classes in the System.IO namespace (or something similar).

e.g.

Code:
StreamWriter sw = new StreamWriter(Application.StartupPath + "/page.html");

sw.Write(data);

sw.Close();

WebBrowser.Navigate(Application.StartupPath + "/page.html");

Not sure if that will work - I just typed it up in the reply box.
 
open new form, load a .html file?
You would use file I/O classes in the System.IO namespace (or something similar).

e.g.

Code:
StreamWriter sw = new StreamWriter(Application.StartupPath + "/page.html");
 
sw.Write(data);
 
sw.Close();
 
WebBrowser.Navigate(Application.StartupPath + "/page.html");

Not sure if that will work - I just typed it up in the reply box.

ok thx for the help... I'll take a look at that later.. don't have time atm and I don't work very much on that project anymore but maybe I'll later... anyway, it's good to know how to do that, so as I said, I will take a look later;)
 
Runescape Gamblingrunescape gambling
Back
Top