Export (0) Print
Expand All

UserControl.MapPath Method

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

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public string MapPath (
	string virtualPath
)
public String MapPath (
	String virtualPath
)
public function MapPath (
	virtualPath : String
) : String
Not applicable.

Parameters

virtualPath

The virtual file path to map.

Return Value

The physical path to the file.

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.

The following example calls the MapPath method to associate an actualServerPath variable with the physical path associated with the user control named myControl.

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


     
myControl.get_Response().Write("<br /><b>The server code is" 
    + "running on machine</b> : "
    + myControl.get_Server().get_MachineName());

String actualServerPath =
    myControl.MapPath(myControl.get_Request().get_Path());

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft