Check for file existence within own site

  • Thread starter Thread starter John
  • Start date Start date
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
 
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
 
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
 
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.


--------------------
 
Back
Top