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

x
?
Solved

Check if File exists over HTTP

Posted on 2006-07-17
3
Medium Priority
?
309 Views
Last Modified: 2008-03-03
Hi,
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)
    {
        try
        {
            if (Web.OpenRead(URL).CanRead == true)
                return true;
        }
        catch
        {
            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,
Soni
0
Comment
Question by:hangar18
[X]
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
3 Comments
 
LVL 7

Expert Comment

by:whityum
ID: 17123041
open an xml data source

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

}catch{
return false;
}

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

Accepted Solution

by:
apresto earned 500 total points
ID: 17123045
Hi hangar18,

Have you considered using the HttpWebRequest/Response objects:

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

Apresto
0
 
LVL 11

Expert Comment

by:jatinderalagh
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
}
0

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