File.Exists always returns false

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
 
G

Guest

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
 
G

Guest

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
 
G

Guest

hi Pete,

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

any other ideas?

Pete
 

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

Top