Page 1 of 1

C# Web Opening.

Posted: Fri Feb 22, 2008 4:12 pm
by Andrew_b
ok i looked in the web tutorial 3 times...might have missed it.
I have a textBox1 and i want to have what ever you type in...it opens it in a web browser (the default browser on the computeR)

I dont know how to do this but and deleted what i had. :P

I had like this (textBox1.ToString); or something..and yes i know thats only the last part.

Posted: Fri Feb 22, 2008 4:34 pm
by LuxuriousMeat
Add this to the top of your code file:

Code: Select all

using System.Diagnostics;
Then use this to open the link in the text box.

Code: Select all

if (Uri.IsWellFormedUriString(textBox1.Text, UriKind.Absolute))
    Process.Start(textBox1.Text);

Posted: Fri Feb 22, 2008 5:26 pm
by Andrew_b
is there a way so it doesnt need the http://www. ?

Posted: Fri Feb 22, 2008 5:43 pm
by Tural
You could always just check if the string has it present, and if not, add it.

Posted: Fri Feb 22, 2008 6:23 pm
by LuxuriousMeat
Or just remove the if i put there. The if just checks if the string in the text box is a valid URL.

Posted: Fri Feb 22, 2008 6:58 pm
by Andrew_b
didnt think of deleting the if. Thanks.