Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to check an url validation but sometimes it takes too much time:

C#
WebClient webClient = new WebClient();
Stream strm = webClient.OpenRead(url);
string req = strm.CanRead.ToString();
Posted
Updated 19-Apr-13 3:44am
v3

1 solution

I think you can easy check whether an URL is valid like this:

C#
WebClient webClient = new WebClient();

try 
{
        Stream strm = webClient.OpenRead(URL);    
        // No exception, so the URL is valid!                               
}
catch (WebException we) {
        // houston we've got a problem (URL invalid)
        throw we;
}


It is enough because if the URL is invalid the exception will be thrown.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900