I need to check the validity of the URL to different files without opening the link document/image. I used the below code in ASP.net 4.7.2 in validation attribute. The current code is as follows : (working fine with jpg)

public override bool IsValid(object DocumentURL)
    {
        try
        {
            string urlLink = (string)DocumentURL;
            WebRequest request = WebRequest.Create(urlLink);
            request.GetResponse();
            return true;
        }
        catch 
        {
            return false;
        }
    }

This works for images but failed when I sent a link to xls file. The error message is :

       "The request entity's media type 'text/plain' is not supported for this resource"
No mediaTypeFormatter is available to read an object of type 'W_Document_URL' media type 'text/plain'."

This looks like my function is trying to open the document. I need only to check the existence of the URL document but does not need to open it. Also if I need to restrict the documents to images(jpeg,png,bmp) and pdf, what is the best way to limit that inside this function?