UserControl.MapPath(String) 方法

定義

將虛擬的檔案路徑 (絕對或相對) 指派給實體檔案路徑。Assigns a virtual file path, either absolute or relative, to a physical file path.

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

要對應的虛擬檔案路徑。The virtual file path to map.

傳回

String

檔案的實體路徑。The physical path to the file.

範例

下列範例會呼叫 MapPath 方法,將 actualServerPath 變數與名為之使用者控制項相關聯的實體路徑產生關聯 myControlThe 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.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 檔案的位置。While similar to the Page.MapPath method, this method maps the path from the .ascx file's location, not the .aspx file's location. 您可以使用這個方法,取得與物件相關聯的影像目錄或其他資源的路徑 UserControlYou can use this method to obtain a path to a directory of images or other resources associated with your UserControl object.

適用於

另請參閱