This documentation is archived and is not being maintained.

UserControl.MapPath Method

Assigns a virtual file path, either absolute or relative, to a physical file path.

[Visual Basic]
Public Function MapPath( _
   ByVal virtualPath As String _
) As String
[C#]
public string MapPath(
 string virtualPath
);
[C++]
public: String* MapPath(
 String* virtualPath
);
[JScript]
public function MapPath(
   virtualPath : String
) : String;

Parameters

virtualPath
The virtual file path to map.

Return Value

The physical path to the file.

Remarks

While similar to the Page.MapPath method, this method maps the path from the .ascx file's location, not the .aspx file's location. You can use this method to obtain a path to a directory of images or other resources associated with your UserControl object.

Example

[Visual Basic, C#] The following example calls the MapPath method to associate an actualServerPath variable with the physical path associated with the user control named myControl.

[Visual Basic] 
myControl.Response.Write("<br><b>The server code is running on machine</b> : " + myControl.Server.MachineName)

Dim actualServerPath As String = myControl.MapPath(myControl.Request.Path)

[C#] 

     myControl.Response.Write("<br><b>The server code is running on machine</b> : " + myControl.Server.MachineName);

     string actualServerPath = myControl.MapPath(myControl.Request.Path);

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

UserControl Class | UserControl Members | System.Web.UI Namespace

Show: