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 相關的影像或其他資源目錄的路徑。