469,934 Members | 2,607 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Determine if a File exists

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
Apr 12 '06 #1
7 3472
Server.MapPath

"Stephen E. Weber" <sw@webersystems.com> wrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
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


Apr 12 '06 #2

"Stephen E. Weber" <sw@webersystems.com> wrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
Example

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


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

Apr 13 '06 #3
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" <no****@nowhere.com> wrote in message
news:c%j%f.72479$%H.41820@clgrps13...

"Stephen E. Weber" <sw@webersystems.com> wrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
Example

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


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

Apr 13 '06 #4
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
"Jeff Dillon" <je********@hotmail.com> wrote in message
news:ul*************@TK2MSFTNGP04.phx.gbl...
Server.MapPath

"Stephen E. Weber" <sw@webersystems.com> wrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
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


Apr 13 '06 #5

"Stephen E. Weber" <sw@webersystems.com> wrote in message
news:OT**************@TK2MSFTNGP02.phx.gbl...
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.

Apr 13 '06 #6
/include/somepath/filename

will always be from the root of the virtual directory

like

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

Jeff

"Homer J Simpson" <no****@nowhere.com> wrote in message
news:c%j%f.72479$%H.41820@clgrps13...

"Stephen E. Weber" <sw@webersystems.com> wrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
Example

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


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

Apr 13 '06 #7
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
"Stephen E. Weber" <sw@webersystems.com> wrote in message
news:uV*************@TK2MSFTNGP05.phx.gbl...
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
"Jeff Dillon" <je********@hotmail.com> wrote in message
news:ul*************@TK2MSFTNGP04.phx.gbl...
Server.MapPath

"Stephen E. Weber" <sw@webersystems.com> wrote in message
news:eQ**************@TK2MSFTNGP03.phx.gbl...
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



Apr 13 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Kamus of Kadizhar | last post: by
2 posts views Thread by OvErboRed | last post: by
6 posts views Thread by Opie | last post: by
2 posts views Thread by Wayne Wengert | last post: by
28 posts views Thread by Tim Daneliuk | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.