[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Check if File exists over HTTP

Posted on 2006-07-17
Medium Priority
Last Modified: 2008-03-03
I need to find whether a file exists in an Http URL or not.
THe code I am currently using is

private bool ReadGraph(string URL)
            if (Web.OpenRead(URL).CanRead == true)
                return true;
            return false;
        return true;

This does not work consistently.
Is there a any other approach or am I missing something here.
Any help on this regard is highly appreciated.
Thanks and Regards,
Question by:hangar18
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 17123041
open an xml data source

                  XmlDataSource xds = new XmlDataSource();
                  xds.DataFile = URL;
                  XmlDocument doc = xds.GetXmlDocument();
                  return true;

return false;

it will throw an error if there is a 404 for the URL.
LVL 23

Accepted Solution

apresto earned 500 total points
ID: 17123045
Hi hangar18,

Have you considered using the HttpWebRequest/Response objects:

HttpWebRequest webRequ = WebRequest.Create( "http://www.google.com" ) as HttpWebRequest;
HttpWebResponse webResp = webRequ.GetResponse();
return true; //because url is found
return false; //because url not found

LVL 11

Expert Comment

ID: 17126392
adding to apresto code check for status code

if(webResp.StatusCode== HttpStatusCode.NotFound)
   // File not found on server
// i.e file does not exist on web server

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question