Possible Duplicate:
How to check that a uri string is valid
I have a text box where user is supposed to enter a URL , How can I programmatically figure out the a URL that user has been entered is valid or not ,If it valid have to process further process else have to enter valid url?
I try this code:
string url = textBox1.Text;
if (!url.StartsWith("http://"))
url = "http://" + url;
Uri myUri;
if(Uri.TryCreate(url,UriKind.RelativeOrAbsolute,out myUri))
{
//use the uri here
}
else
{
MessageBox.Show("Please Enter the Absolute URL name");
textBox1.Clear();
textBox1.Focus();
}