File.Exists always returns false

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a website sitting on a server (ServerA) with images to be
displayed sitting on a separate server (ServerB) on the same network.

I am trying to test for the existance of an image using:

File.Exists(Server.Path("/images/" + "myImage.jpg")

where the folder "images" is the virtual folder where the images are
stored.

Server.Path ("/images/" + "myImage.jpg") returns, as expected, the path on
ServerB in the form: "\\ServerB\...\Images\myImage.jpg"

However, although the image does exist and displays on the webpage, the
File.Exists returns False.

Am I doing something fundamentally wrong here?

Many thanks for any help.

Pete
 
Italian Pete,
You might wanna check with the Don about this.
It's not
File.Exists(Server.Path("/images/" + "myImage.jpg")
It's
File.Exists(Server.MapPath("/images/" + "myImage.jpg")


Peter
 
The funny thing about File.Exists is that it seems the original developer was
determined to return a bool and not an exception so it swallows some usefull
exceptions like security exceptions and just returns false. It can be usefull
to comment out that line of code and try to open the file with a file stream
or something, this may then throw some security exception and give you a real
error message to work on.

HTH

Ciaran O'Donnell
 
hi Pete,

Sorry, that was my typo, I did in fact mean Server.MapPath (which didn't
work).

any other ideas?

Pete
 
Back
Top