Mega Code Archive

 
Categories / C# / Network
 

Is Link Valid

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.Specialized; using System.Text.RegularExpressions; using System.Net; public static class LinkCheckerUtilities {     public static bool LinkIsValid(Uri UrlToCheck)     {         bool ReturnValue = true;         if ((UrlToCheck.Scheme == "http") || (UrlToCheck.Scheme == "https"))         {             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(UrlToCheck);             request.Credentials = CredentialCache.DefaultCredentials;             HttpWebResponse response = null;             try             {                 response = (HttpWebResponse)request.GetResponse();                 response.Close();             }             catch (WebException ex)             {                 ReturnValue = false;             }             finally             {                 if (response != null)                 {                     response.Close();                 }             }         }         return ReturnValue;     } }