Reputation:
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
.
Upvotes: 5
Views: 26966
Reputation: 5981
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.
Upvotes: 8
Reputation: 8084
WbBrowser.Url is of type Uri so you need to use
WbBrowser.Url = new Uri(link);
Upvotes: 11