Welcome to WebmasterWorld Guest from 54.158.228.55

Forum Moderators: ocean10000

Message Too Old, No Replies

why is mapPath necessary?

     
8:58 pm on Mar 14, 2006 (gmt 0)

10+ Year Member



why will this work:


Filepath = Server.MapPath("readme.txt");
fs.FileExists(Filepath)...

but not this:


fs.FileExists("readme.txt")

1:44 pm on Mar 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because the FileExists() method needs to know the location of the file you'd like to determine existance on.
5:39 pm on Mar 15, 2006 (gmt 0)

10+ Year Member



Isn't that what paths are for:

../here/here/file

is a location

and:

file.ext

is file in the current directory. Unles asp doesn't like relative paths... I don't get it.

5:46 pm on Mar 15, 2006 (gmt 0)

10+ Year Member



Like EasyCoder stated, fs.FileExists needs a full path for which to find the file. ie

fs.FileExists("readme.txt") will not work,

fs.FileExists("../yourdir/readme.txt") will not work,

But this will.
fs.FileExists("C:\inetpub\wwwroot\yourdir\readme.txt")

So when you use Sever.MapPath you are literally using the easy way to providing a full path to fs.FileExists.

Use this to get the full path as the server sees it:
response.write Server.MapPath("readme.txt")

12:54 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Keep in mind that the File System Object is executing somewhere from the System32 or another system folder, not your website folder. So the FileExists method needs to take that into account.

If the method worked the way you've asked here's what would happen... (psuedo code)

public bool FileExists(string in_relativeFileName)
{
// determine if in_relativeFileName lives in system32
return (bool) if exists relativeFileName in system32? true : false;
}

versus...
public bool FileExists(string in_absoluteFileName)
{
// determine if in_absoluteFileName lives specified location
return (bool) if exists absoluteFileName in specified location? true : false;
}

 

Featured Threads

Hot Threads This Week

Hot Threads This Month