UserControl.MapPath(String) 方法

定義

將虛擬的檔案路徑 (絕對或相對) 指派給實體檔案路徑。

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

要對應的虛擬檔案路徑。

傳回

String

檔案的實體路徑。

範例

下列範例會呼叫 方法, MapPath 將變數與名為 myControl 的使用者控制項相關聯的實體路徑產生關聯 actualServerPath


          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 物件相關聯的其他資源。

適用於

另請參閱