top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

What is Server.MapPath?

+1 vote
23 views
What is Server.MapPath?
posted Jun 12, 2017 by Rohini Agarwal

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes

The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.

MapPath(
   Path
)

Parameters

Path

Specifies the relative or virtual path to map to a physical directory. If Path starts with either a forward (/) or backward slash (), the MapPath method returns a path as if Path were a full, virtual path. If Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the .asp file being processed.

Return Values

This method has no return values.

The MapPath method returns the ASP 0173 error, "Invalid Path Character", if the Path parameter contains any of the following

characters:

Asterisk (*)

Question mark (?)

Angle brackets (< or >)

Comma (,)

Colon or semi-colon (: or ;)

Single-quote or double-quote (' or ")

Right square bracket (])

Double slashes (// or \\)

This method does not check whether the path it returns is valid or exists on the server. MapPath is not available to the Session_OnEnd and the Application_OnEnd events.

Because the MapPath method maps a path regardless of whether the specified directories currently exist, you can use the MapPath method to map a path to a physical directory structure, and then pass that path to a component that creates the specified directory or file on the server.

Caution:

For security reasons, the AspEnableParentPaths property has a default value set to FALSE. Scripts will not have access to the physical directory structure unless AspEnableParentPaths is set to TRUE.

Example Code

The following example uses the server variable PATH_INFO to map the physical path of the current file.

VBScript

<%= Server.MapPath(Request.ServerVariables("PATH_INFO"))%><BR> 

Because the path parameters in the following examples do not start with a slash character, they are mapped relative to the directory that contains the example file.

VBScript

<%= Server.MapPath("data.txt")%><BR> 
<%= Server.MapPath("script/data.txt")%><BR> 

The following example will retrieve the path to the current directory.

VBScript

<%= Server.MapPath(".")%><BR> 

The following example will retrieve the path to the parent directory. (Note: This will return an error if parent paths are disabled for ASP.)

VBScript

<%= Server.MapPath("..")%><BR> 
answer Jun 13, 2017 by Manikandan J
Similar Questions
+1 vote

I am trying to get all the collection names from MongoDb server using C# code using db.GetCollectionNames() method.

I have 12 collections in my database, but the above method returns an empty list. I have verified that I am referring to the correct database. What am I doing wrong? Or if there is an alternate way?

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...