homepage Welcome to WebmasterWorld Guest from 50.17.107.233
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
why is mapPath necessary?
benlieb




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

why will this work:


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

but not this:


fs.FileExists("readme.txt")


 

Easy_Coder




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

Because the FileExists() method needs to know the location of the file you'd like to determine existance on.

benlieb




msg:954760
 5:39 pm on Mar 15, 2006 (gmt 0)

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.

lZakl




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

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")

Easy_Coder




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

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;
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved