943,779 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 1781
  • C# RSS
Dec 6th, 2008
0

Displaying a local webpage

Expand Post »
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:
C# Syntax (Toggle Plain Text)
  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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
FlamingBlade is offline Offline
7 posts
since Mar 2007
Dec 6th, 2008
0

Re: Displaying a local webpage

Try putting your slashes round the correct way, eg

file://webpage/whatever.html
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 6th, 2008
0

Re: Displaying a local webpage

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
FlamingBlade is offline Offline
7 posts
since Mar 2007
Dec 6th, 2008
0

Re: Displaying a local webpage

The Uri type is not string so you have to implement the code as follow
C# Syntax (Toggle Plain Text)
  1. webBrowser1.Url = new Uri( "file:\\webpage\Maphs v1.htm");
Reputation Points: 11
Solved Threads: 16
Junior Poster
Jugortha is offline Offline
172 posts
since Oct 2007
Dec 7th, 2008
0

Re: Displaying a local webpage

I just tried that. It compiled successfully but I got the following error at runtime:
Quote ...
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...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
FlamingBlade is offline Offline
7 posts
since Mar 2007
Dec 7th, 2008
0

Re: Displaying a local webpage

Perhaps you could try webBrowser1.Navigate(urlstring) instead of webBrowser1.Url.
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,738 posts
since Oct 2008
Dec 7th, 2008
0

Re: Displaying a local webpage

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"?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 7th, 2008
0

Re: Displaying a local webpage

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
FlamingBlade is offline Offline
7 posts
since Mar 2007
Dec 7th, 2008
0

Re: Displaying a local webpage

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
FlamingBlade is offline Offline
7 posts
since Mar 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: error opening excel sheet in c#
Next Thread in C# Forum Timeline: Plotting distance to an image





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC