Determine if a File exists

  • Thread starter Thread starter Stephen E. Weber
  • Start date Start date
S

Stephen E. Weber

I need to determine if a file exists using code.

I tried using the system.io.file.exists function, that will appears to
locate the file if I use the complete filespec, when I move the project to
the web server, that command will not work because I can not specify the
entire path, just the path relative to the default project folder.

Example

This is the path my image property uses: "~/image/NoImageAvailable.jpg"

If I use the above system.io.file.exists fails

if I use the full filespec: " E:\Documents and Settings\Steve\My
Documents\Visual Studio 2005\WebSites\GshockWatch\NoImageAvailable.jpg"

If I use the above system.io.file.exists succeeds.

You see how the second example would not work on an ISPs server.

any suggestions.
thanks
steve
 
Example

This is the path my image property uses: "~/image/NoImageAvailable.jpg"

That's a Unix path definition. It means [HOME]/image/NoImageAvailable.jpg
 
Thanks for the advise and information!

ok, that makes sense, I assume in Windows land I can use the ".." for
current folder, do you know if there is a specification for home folder in
windows land?

thanks


Steve

Homer J Simpson said:
Example

This is the path my image property uses: "~/image/NoImageAvailable.jpg"

That's a Unix path definition. It means [HOME]/image/NoImageAvailable.jpg
 
Thanks for the tip, but in this case i dont think its gonna apply, I know
what the entire path of the file from the root is, which is what this
command appears to return, I need a way to specify the path from the home
folder on the web site, on most servers I dont have access to the full root
and they differ, Im trying to use a path that will work on any server.

thanks
 
Thanks for the advise and information!

ok, that makes sense, I assume in Windows land I can use the ".." for
current folder, do you know if there is a specification for home folder in
windows land?

Actually . is the current folder, .. is the parent (just like Unix -- which
Gates copied from)

"Special' folders, like My Documents, do have specific .Net names. I've seen
that question answered here before. However there is no real 'Home' folder
in Dos/Windows etc.

See "My.Computer.FileSystem.SpecialDirectories Object Members" and
"My.Computer.FileSystem.SpecialDirectories Property" for the paths etc.
 
That doesn't make any sense. Either server.mappath will give you the fully
qualified path, or simply a relative path from the root will always work too

File.IO needs the fully qualified path.

Jeff
 
/include/somepath/filename

will always be from the root of the virtual directory

like

c:\inetpub\wwwroot\vdir\include\sompath

Jeff

Homer J Simpson said:
Example

This is the path my image property uses: "~/image/NoImageAvailable.jpg"

That's a Unix path definition. It means [HOME]/image/NoImageAvailable.jpg
 
Back
Top