ALP Server.MapPath method
Maps a virtual or relative path to a physical path.

Syntax:

Server.MapPath( string )

Parameters:

string - string containing the path to be translated

The method returns new string containing the physical path corresponding to the path (virtual) in the passed parameter (see Syntax for details).

Examples:

JScript/VBScript:

<%= Server.MapPath("/databases/database1.mdb") %>

This is the the important one method in the Server object. Using it the script application can be made portable without need of reconfiguration. On the WEB servers applications are not moved frequently and need of that method is not so important but scripts executed by the ALP need much more portability thus we recommend to use the MapPath method in any place where the path to a resource is required.

Syntax:

Passed parameter can contain full virtual path - relative to the root of the ALP site or relative path that roots in the directory of the script being executed.

Lets get an example environment - ALP site in the subtree of the C:\site, and script in the C:\site\scripts\script.asp. The script wants to use (somehow) a file located in the C:\site\scripts\dir1\file.some. It calls MapPath with a relative path:

Server.MapPath("dir1/file.some")

This returns: C:\site\scripts\dir1\file.some

Script also can call the MapPath with full virtual path:

Server.MapPath("/scripts/dir1/file.some")

That will produce the same result. If the ASP script uses some include files or if the raw ScriptGen script uses some libraries Server.MapPath called in these files will assume the context/location of the executed script not the location of the included file. It is appropriate to use the MapPath in the include/library script files only with full virtual paths - in other case result of the mapping will differ depending on the script that is executed and includes that include file/library. As an exception sometimes this technique (passing relative path to MapPath in the include file) can be useful to allow different scripts using the same include file to use different resources - i.e. your site probably contains several branches/subtrees with similar structure but with different files.

Remarks:

Using MapPath with relative paths depends on the (int)EnableParentPaths value in the alp.application specified in sections managed by the ScriptGen content generator. If its value is 0 or the value not present MapPath will rise an exception if the passed parameter contains ".." characters - i.e. accesses parent paths.

Applies to: Server object

See also: ASP includes, ScriptGen raw scripts, ScriptGen configuration

newObjects Copyright newObjects 2001-2004