Hello,

Thanks for the comments.

This is working fine.

But does it efficient?

I have to review a big directory and issue a report if I expect files and
they are not there.

Does working with Ajax like this is better (more efficient)?

                       

xmlhttp.open("HEAD", "full.tif",true);

xmlhttp.onreadystatechange=function() {

 if (xmlhttp.readyState==4) {

                       if (xmlhttp.status==200) alert("URL Exists!")

                       else if (xmlhttp.status==404) alert("URL doesn't
exist!")

                             else alert("Status is "+xmlhttp.status)

                       }

 }

xmlhttp.send(null)

 

Thanks,

Lior.

 

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Ryan Heath
Sent: Wednesday, September 06, 2006 11:51 AM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] determine if a tiff file exists on a url
location

 

File.Exists checks your hd whether the file is there or not.

Testing whether a file exists on the internet is something completely
different.

 

You might do something with WebRequest, to see if the server is
responding...

 

static bool Exists(string url)

{

      try

      {                       

      WebRequest wb = WebRequest.Create(url);

      using ( WebResponse rp = wb.GetResponse())

      {

            HttpWebResponse hrp = rp as HttpWebResponse;

            if ( hrp != null)

            {

                  return hrp.StatusCode == HttpStatusCode.OK;

            }

            else

            {

                  return false;

            }

      }

      }

      catch( WebException)

      {

            return false;

      }

}

 

I made a few assumptions here, but it should get you started, then

again getting a file from the internet is really something else as

getting it from your hd...

 

HTH

// Ryan

 

On 9/6/06, Lior Levy <[EMAIL PROTECTED]> wrote:

> Hello,

> 

> 

> 

> I want to determine if a tiff file exists on a url location.

> 

> 

> 

> The File Class is no good because the path can't be a url.

> 

> only "c:\\MyDir\\MyFile.txt" or "\\\\MyServer\\MyShare"

> 

> 

> 

> path = "http://www.serverName.com/folder/aaa.tiff";;

> 

> lbl_ans.Text = File.Exists(path).ToString();

> 

> 

> 

> Any idea?

> 

> Thanks,

> 

> Lior

> 

> ===================================

> This list is hosted by DevelopMentor(r)  http://www.develop.com

> 

> View archives and manage your subscription(s) at
http://discuss.develop.com

> 

 

===================================

This list is hosted by DevelopMentorĀ®  http://www.develop.com

 

View archives and manage your subscription(s) at http://discuss.develop.com


===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to