473,734 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File.Exists always returns false

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(Ser ver.Path("/images/" + "myImage.jp g")

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

Server.Path ("/images/" + "myImage.jp g") 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
Sep 11 '06 #1
4 13437
Italian Pete,
You might wanna check with the Don about this.
It's not
File.Exists(Ser ver.Path("/images/" + "myImage.jp g")
It's
File.Exists(Ser ver.MapPath("/images/" + "myImage.jp g")
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Italian Pete" wrote:
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(Ser ver.Path("/images/" + "myImage.jp g")

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

Server.Path ("/images/" + "myImage.jp g") 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
Sep 11 '06 #2
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

"Italian Pete" wrote:
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(Ser ver.Path("/images/" + "myImage.jp g")

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

Server.Path ("/images/" + "myImage.jp g") 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
Sep 11 '06 #3
hi Pete,

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

any other ideas?

Pete
"Peter Bromberg [C# MVP]" wrote:
Italian Pete,
You might wanna check with the Don about this.
It's not
File.Exists(Ser ver.Path("/images/" + "myImage.jp g")
It's
File.Exists(Ser ver.MapPath("/images/" + "myImage.jp g")
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Italian Pete" wrote:
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(Ser ver.Path("/images/" + "myImage.jp g")

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

Server.Path ("/images/" + "myImage.jp g") 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
Sep 11 '06 #4
Yes,
aside from Ciaran's exellent comments, wrap your call in a try /catch block
anyway and output any exception message and stacktrace.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Italian Pete" wrote:
hi Pete,

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

any other ideas?

Pete
"Peter Bromberg [C# MVP]" wrote:
Italian Pete,
You might wanna check with the Don about this.
It's not
File.Exists(Ser ver.Path("/images/" + "myImage.jp g")
It's
File.Exists(Ser ver.MapPath("/images/" + "myImage.jp g")
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Italian Pete" wrote:
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(Ser ver.Path("/images/" + "myImage.jp g")
>
where the folder "images" is the virtual folder where the images are
stored.
>
Server.Path ("/images/" + "myImage.jp g") 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
Sep 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3929
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in displaying them on the delete page. you can see it in action at www.4am.com.au/gallery/upload.php...
18
3178
by: Dan | last post by:
I have code like the following to test for existence of a file. I know the file is there, but File.Exists returns FALSE. The problem appears to be that the file is in a directory beneath "My Documents". When I move it to a directory directly under the root, File.Exists returns TRUE. So I tried using FileIOPermission to give me rights to read it, but still no luck. Any suggestions? Thanks... FileIOPermission f = new...
2
14405
by: Chris Fink | last post by:
I am using the System.IO.File class to determine if a file exists on a network share. The File.Exists method keeps returning false, even though the file does exist. The MSDN documentation states, "If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path."
13
4317
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I cleanup files that were uploaded -- but obviously left stranded when the users aborted/gave up writting...
1
5393
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved completely/succsessfully on the client's computer before updating some metadata on the server (file downloaded date for instance) However, All examples i have tried, and all examples I have found that other people says works - doesn't work for me :-(
5
3789
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public List<RoleData> GetRoles() { return GetRoles(null, false); }
12
4560
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function work for the file which is located in a direcotry with a white space? Thanks!
7
19104
by: sprash | last post by:
Newbie question: I'm trying to determine if a file physically exists regardless of the permissions on it Using File.Exists() returns false if it physically exists but the process does not have the necessary permissions. One hack could be to check for length and that would throw a FileNotFoundException ...but there is got to be a better way!
8
3632
by: stef mientki | last post by:
hello, I've written a convenience wrapper around ConfigObj (which is a imporved ConfigParser). Now if I use an instance of the base class, I can easily test is the instance exists by " if ini:", like in this example ini = None
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.