UserControl.MapPath(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将虚拟文件路径(绝对路径或相对路径)分配给物理文件路径。
public:
System::String ^ MapPath(System::String ^ virtualPath);
public string MapPath(string virtualPath);
member this.MapPath : string -> string
Public Function MapPath (virtualPath As String) As String
参数
- virtualPath
- String
要映射的虚拟文件路径。
返回
文件的物理路径。
示例
以下示例调用该方法将MapPath变量与与命名actualServerPath的用户控件关联的物理路径相关联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.Response.Write("<br /><b>The server code is running on machine</b> : " + myControl.Server.MachineName)
Dim actualServerPath As String = myControl.MapPath(myControl.Request.Path)
注解
此方法与 Page.MapPath 方法类似,但此方法从 .ascx 文件的位置映射路径,而不是.aspx文件的位置。 可以使用此方法获取图像目录或与对象 UserControl 关联的其他资源的路径。