Displaying a local webpage

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2007
Posts: 7
Reputation: FlamingBlade is an unknown quantity at this point 
Solved Threads: 0
FlamingBlade FlamingBlade is offline Offline
Newbie Poster

Displaying a local webpage

 
0
  #1
Dec 6th, 2008
I can't figure out how to display a local webpage. I've tried messing with the webBrowser control but it keeps adding "http://" to the front of the local webpage address, and if I try to change it from within the code like this:
  1. webBrowser1.Url = "file:\\webpage\Maphs v1.htm";
I get the following error:
error CS1009: Unrecognized escape sequence

Can anyone help me out? The page I want to display is just one page, and it is stored locally in the same folder as the program.

Thanks in advance for any help!
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Displaying a local webpage

 
0
  #2
Dec 6th, 2008
Try putting your slashes round the correct way, eg

file://webpage/whatever.html
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 7
Reputation: FlamingBlade is an unknown quantity at this point 
Solved Threads: 0
FlamingBlade FlamingBlade is offline Offline
Newbie Poster

Re: Displaying a local webpage

 
0
  #3
Dec 6th, 2008
Thanks for your response. I was experimenting with them the otherway round.

If I had them the correct way, I'd get this error:

error CS0029: Cannot implicitly convert type 'string' to 'System.Uri'


Any ideas?
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 172
Reputation: Jugortha is an unknown quantity at this point 
Solved Threads: 16
Jugortha Jugortha is offline Offline
Junior Poster

Re: Displaying a local webpage

 
0
  #4
Dec 6th, 2008
The Uri type is not string so you have to implement the code as follow
  1. webBrowser1.Url = new Uri( "file:\\webpage\Maphs v1.htm");
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 7
Reputation: FlamingBlade is an unknown quantity at this point 
Solved Threads: 0
FlamingBlade FlamingBlade is offline Offline
Newbie Poster

Re: Displaying a local webpage

 
0
  #5
Dec 7th, 2008
I just tried that. It compiled successfully but I got the following error at runtime:
Windows cannot access \\webpage\Maphs v1.htm
...
The network path was not found.
The file DOES exist at that location, which is all the more confusing...
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,955
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 282
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: Displaying a local webpage

 
0
  #6
Dec 7th, 2008
Perhaps you could try webBrowser1.Navigate(urlstring) instead of webBrowser1.Url.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Displaying a local webpage

 
0
  #7
Dec 7th, 2008
The file wont be at \\webpage\blah.htm, its at c:\webpage\blah.html
the \\something notation usually means machine name, is your PC really called "webpage"?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 7
Reputation: FlamingBlade is an unknown quantity at this point 
Solved Threads: 0
FlamingBlade FlamingBlade is offline Offline
Newbie Poster

Re: Displaying a local webpage

 
0
  #8
Dec 7th, 2008
ddanbe: I tried "webBrowser1.Navigate(webpage/Maphs v1.htm)", that gave me a 404.

LizR:
The HTML file is in a directory called "webpage", which is in the same directory as the program.

I wanted a local reference to the file, so that if I wanted to move the program's directory, it would work anyway. Evidently, that didn't happen.
Is there a way to make a local reference like that? Or should I just give up and hardcode the path in (which works)?
Last edited by FlamingBlade; Dec 7th, 2008 at 11:44 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 7
Reputation: FlamingBlade is an unknown quantity at this point 
Solved Threads: 0
FlamingBlade FlamingBlade is offline Offline
Newbie Poster

Re: Displaying a local webpage

 
0
  #9
Dec 7th, 2008
You got me thinking about the location, and with some googling, I solved it.

I used "Application.ExecutablePath" to give me the location of the executable as a string, then added "webpage/maphs v1.htm" to it and used that - the webpage now displays.

Thanks for the help.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC