UserControl.MapPath(String) 方法

定義

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

C#
public string MapPath (string virtualPath);

參數

virtualPath
String

要對應的虛擬檔案路徑。

傳回

String

檔案的實體路徑。

範例

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

C#

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

備註

雖然與 方法類似 Page.MapPath ,但這個方法會對應 .ascx 檔案位置的路徑,而不是 .aspx 檔案的位置。 您可以使用這個方法來取得影像目錄的路徑,或與您的 UserControl 物件相關聯的其他資源。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

另請參閱