views:

436

answers:

3

I'm using a Web Browser control in C# and I'd like to be able to plug in different URLs depending on other things that have happened in the program. How can I set the URL property to a string in the code? Can I convert a string to the System.Uri type?

string link;
string searchedtitle = "The+Italian+Job";
link = "http://www.imdb.com/find?s=all&q=" + searchedtitle + "&x=0y=0";
WbBrowser.Url = link; // This is what I don't know how to do

Something to that effect would be ideal, where I could change 'searchedtitle' within the program somewhere else and still have it run properly. Unfortunately, the Url property is of type System.Uri, and I only have a System.String.

+3  A: 

WbBrowser.Url is of type Uri so you need to use

WbBrowser.Url = new Uri(link);
Mikko Rantanen
A: 

Did you ever find the documentation of the Url property? I know how difficult this sort of thing can be to find.


Maybe you actually didn't know how to convert from a string to a System.Uri? I'd feel better to learn that you aren't actually too lazy to look up the documentation on the Url property. Instead, it would simply mean that you're not good at formulating questions, which is a much lesser offense.

John Saunders
That was, I suppose, my problem. Sorry, I did read up on the URL property, but I wasn't sure how to convert, or if there was another way to do it. Should have phrased my question differently.
vcstr
+3  A: 

Note that setting the URL is exactly the same as calling the Navigate() function. Navigate takes a string as an argument as the URL, eliminating the step of converting your URL to a string.

Robert Venables
I suppose that should have been apparent. Thank you for your help, problem solved.
vcstr