Find out if an URL exists – C#
filed in C# on Feb.05, 2010
Trying to find out if the url is valid ? Use the following code:
public static bool urlExist(string url)
{
WebRequest webRequest = WebRequest.Create(url);
WebResponse webResponse;
webRequest.Timeout = 1500; // Max timeout
try
{
webResponse = webRequest.GetResponse();
}
catch //If exception thrown then couldn't get response from address
{
return false;
}
return true;
}
Leave a Reply