Tags

,


Remot Server File Exist or not

 

To chek the File Exist or not on Remote Server, the code the following,

This code is tested and can check the any file exist of not,

in case of file not exist it return the 404 error, file not exist.

 

  WebRequest request;

        WebResponse response;

        String strMSG = string.Empty;

        request = WebRequest.Create(new Uri(“http://www.tradeget.com/images/topimg.jpg”));

        request.Method = “HEAD”;

        try

        {

            response = request.GetResponse();

            strMSG = string.Format(“{0} {1}”, response.ContentLength, response.ContentType);

        }

        catch (Exception ex)

        {

            //In case of File not Exist Server return the (404) Error

            strMSG = ex.Message;

        }

 

        lblMSG.Text = strMSG;

 

Enjoy!

Advertisements