Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > finding if a file exists

Reply
Thread Tools

finding if a file exists

 
 
Carlos
Guest
Posts: n/a
 
      10-20-2009
Hi all,

I need to find out if a file exists given a local, or remote path. That is,
if it resides the local machine, the network, or in a given URL . Is there
any way to do that?

Thanks in advance,

Carlos.


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-20-2009
On Oct 20, 4:46*pm, "Carlos" <caher...@yahoo.com> wrote:
> Hi all,
>
> *I need to find out if a file exists given a local, or remote path. That is,
> if it resides the local machine, the network, or in a given URL . Is there
> any way to do that?
>
> Thanks in advance,
>
> * Carlos.


if (s.StartsWith("http") || s.StartsWith("ftp"))
.... remote path
elseif ( s.StartsWith("\\") )
.... network path
else
.... local
 
Reply With Quote
 
 
 
 
Carlos
Guest
Posts: n/a
 
      10-20-2009
Hi again Alexey,

thanks for your prompt response. However, could you also please fill in the
blanks for those conditions. In other words, how would I check for the
existence in the URL path, and network. I know I just can use
system.io.file.exists for local resources.

Thanks again,

Carlos.

"Alexey Smirnov" <> wrote in message
news:577d5fb6-4c16-4033-8caa-...
On Oct 20, 4:46 pm, "Carlos" <caher...@yahoo.com> wrote:
> Hi all,
>
> I need to find out if a file exists given a local, or remote path. That
> is,
> if it resides the local machine, the network, or in a given URL . Is there
> any way to do that?
>
> Thanks in advance,
>
> Carlos.


if (s.StartsWith("http") || s.StartsWith("ftp"))
.... remote path
elseif ( s.StartsWith("\\") )
.... network path
else
.... local


 
Reply With Quote
 
David
Guest
Posts: n/a
 
      10-20-2009
You would do a web request to try the file, and if it returns a 404 error,
it is not there.

It might also be worth checking other responses that 200, for example, a 301
or a 302 is a redirect.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


"Carlos" <> wrote in message
news:...
> Hi again Alexey,
>
> thanks for your prompt response. However, could you also please fill in
> the blanks for those conditions. In other words, how would I check for the
> existence in the URL path, and network. I know I just can use
> system.io.file.exists for local resources.
>
> Thanks again,
>
> Carlos.
>
> "Alexey Smirnov" <> wrote in message
> news:577d5fb6-4c16-4033-8caa-...
> On Oct 20, 4:46 pm, "Carlos" <caher...@yahoo.com> wrote:
>> Hi all,
>>
>> I need to find out if a file exists given a local, or remote path. That
>> is,
>> if it resides the local machine, the network, or in a given URL . Is
>> there
>> any way to do that?
>>
>> Thanks in advance,
>>
>> Carlos.

>
> if (s.StartsWith("http") || s.StartsWith("ftp"))
> ... remote path
> elseif ( s.StartsWith("\\") )
> ... network path
> else
> ... local
>



 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-20-2009
On Oct 20, 7:18*pm, "David"
<david.colliver.N...@revilloc.REMOVETHIS.com> wrote:
> You would do a web request to try the file, and if it returns a 404 error,
> it is not there.
>
> It might also be worth checking other responses that 200, for example, a 301
> or a 302 is a redirect.
>
> --
> Best regards,
> Dave Colliver.http://www.AshfieldFOCUS.com
> ~~http://www.FOCUSPortals.com- Local franchises available
>
> "Carlos" <caher...@yahoo.com> wrote in message
>
> news:...
>
>
>
> > Hi again Alexey,

>
> > thanks for your prompt response. However, could you also please fill in
> > the blanks for those conditions. In other words, how would I check for the
> > existence in the URL path, and network. I know I just can use
> > system.io.file.exists for local resources.

>
> > Thanks again,

>
> > * Carlos.

>
> > "Alexey Smirnov" <alexey.smir...@gmail.com> wrote in message
> >news:577d5fb6-4c16-4033-8caa-....
> > On Oct 20, 4:46 pm, "Carlos" <caher...@yahoo.com> wrote:
> >> Hi all,

>
> >> I need to find out if a file exists given a local, or remote path. That
> >> is,
> >> if it resides the local machine, the network, or in a given URL . Is
> >> there
> >> any way to do that?

>
> >> Thanks in advance,

>
> >> Carlos.

>
> > if (s.StartsWith("http") || s.StartsWith("ftp"))
> > ... remote path
> > elseif ( s.StartsWith("\\") )
> > ... network path
> > else
> > ... local- Hide quoted text -

>
> - Show quoted text -


Carlos,

try like Dave suggested

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create
("http://....");
webRequest.AllowAutoRedirect = false;
try
{
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
Response.Write(response.StatusCode.ToString()); // Returns "OK",
"Moved", "MovedPermanently", etc
}
catch (WebException ex)
{
Response.Write(ex.Message); // File does not exist
}

Hope this helps
 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      10-20-2009
On Oct 20, 6:04*pm, "Carlos" <caher...@yahoo.com> wrote:
> Hi again Alexey,
>
> *thanks for your prompt response. However, could you also please fill in the
> blanks for those conditions. In other words, how would I check for the
> existence in the URL path, and network. I know I just can use
> system.io.file.exists for local resources.
>


Regarding network check. system.io.file.exists should work there too,
but you have to be aware of access rights from ASP.net process to the
shared resource.

if (System.IO.File.Exists(@"\\Server\Folder\File.txt" )) {
....
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if a directory exists? folder.exists() does not work! Ulf Meinhardt Java 8 08-28-2009 12:26 PM
Finding out if a folder exists christopher_board@yahoo.co.uk Java 2 02-05-2007 06:07 PM
finding if file exists or not in apache webdav server and if exists what is the mime type of it.... Totan Java 0 04-17-2006 05:13 AM
Finding if an value exists in a DD list Stu ASP .Net 1 05-20-2004 06:43 PM
Finding if a certain form elements exists... Stu ASP .Net 4 08-19-2003 01:10 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57