Home All Groups Group Topic Archive Search About

Determine if a File exists

Author
12 Apr 2006 10:05 PM
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

Author
12 Apr 2006 10:10 PM
Jeff Dillon
Server.MapPath

Show quoteHide quote
"Stephen E. Weber" <s*@webersystems.com> wrote in message
news:eQYnD1nXGHA.1476@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
>
>
Author
13 Apr 2006 2:04 PM
Stephen E. Weber
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


Show quoteHide quote
"Jeff Dillon" <jeffdil***@hotmail.com> wrote in message
news:ul63q3nXGHA.196@TK2MSFTNGP04.phx.gbl...
> Server.MapPath
>
> "Stephen E. Weber" <s*@webersystems.com> wrote in message
> news:eQYnD1nXGHA.1476@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
>>
>>
>
>
>
Author
13 Apr 2006 4:53 PM
Jeff Dillon
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
Show quoteHide quote
"Stephen E. Weber" <s*@webersystems.com> wrote in message
news:uV20tMwXGHA.128@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" <jeffdil***@hotmail.com> wrote in message
> news:ul63q3nXGHA.196@TK2MSFTNGP04.phx.gbl...
>> Server.MapPath
>>
>> "Stephen E. Weber" <s*@webersystems.com> wrote in message
>> news:eQYnD1nXGHA.1476@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
>>>
>>>
>>
>>
>>
>
>
Author
13 Apr 2006 3:58 AM
Homer J Simpson
"Stephen E. Weber" <s*@webersystems.com> wrote in message
news:eQYnD1nXGHA.1476@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
Author
13 Apr 2006 1:51 PM
Stephen E. Weber
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" <nob***@nowhere.com> wrote in message
news:c%j%f.72479$%H.41820@clgrps13...
Show quoteHide quote
>
> "Stephen E. Weber" <s*@webersystems.com> wrote in message
> news:eQYnD1nXGHA.1476@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
>
>
>
Author
13 Apr 2006 4:39 PM
Homer J Simpson
"Stephen E. Weber" <s*@webersystems.com> wrote in message
news:OTx0hFwXGHA.4484@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.
Author
13 Apr 2006 4:55 PM
Jeff Dillon
/include/somepath/filename

will always be from the root of the virtual directory

like

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

Jeff

"Homer J Simpson" <nob***@nowhere.com> wrote in message
news:c%j%f.72479$%H.41820@clgrps13...
Show quoteHide quote
>
> "Stephen E. Weber" <s*@webersystems.com> wrote in message
> news:eQYnD1nXGHA.1476@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
>
>
>