| Welcome to WebmasterWorld Guest from 22.214.171.124 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|why is mapPath necessary?|
why will this work:
Filepath = Server.MapPath("readme.txt");
but not this:
Because the FileExists() method needs to know the location of the file you'd like to determine existance on.
Isn't that what paths are for:
is a location
is file in the current directory. Unles asp doesn't like relative paths... I don't get it.
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. 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:
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;
public bool FileExists(string in_absoluteFileName)
// determine if in_absoluteFileName lives specified location
return (bool) if exists absoluteFileName in specified location? true : false;
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved