Check for file existence within own site

J

John

Hi there,

I have a method in a code behind class that, given a string, checks to see
if the respective file exists within the same site. I'm using this:

System.IO.File.Exists(strFilePath)

....but is that the right way to check for a file in your own site and if so
does strFilePath need to be in a particular format?

Thanks in advance.

John
 
K

Kevin Spencer

If you're looking for a file that should be on the same machine, and your
app has the proper file system permissions, that is a perfectly fine way to
check for its existence. Otherwise, you can create an HttpRequest, and see
if you get a 404 (Not Found) Response code.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
J

John

Hello Kevin,

Thanks for your reply. When I say file, I mean I'm checking the existance
of another page (MyPage.aspx) within the site. Does that change things?

Thanks

John
 
S

Steven Cheng[MSFT]

Hi John,

As you mentioned, the code is used in page codebehind. So that checking
page is in the same web application of other pages you want to check(or at
least on the same server machine)? If so, I agree that the System.IO
components are the proper approach here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top