ASPMapPathメソッド_
❮完全なサーバーオブジェクトリファレンス
MapPathメソッドは、指定されたパスを物理パスにマップします。
注:このメソッドは、Session.OnEndおよびApplication.OnEndでは使用できません。
構文
Server.MapPath(path)
Parameter | Description |
---|---|
path | Required. A relative or virtual path to map to a physical path. If this parameter starts with / or \, it returns a path as if this parameter is a full virtual path. If this parameter doesn't start with / or \, it returns a path relative to the directory of the .asp file being processed |
例
例1
以下の例では、ファイル「test.asp」はC:\ Inetpub \ Wwwroot \ Scriptにあります。
ファイル「test.asp」(C:\ Inetpub \ Wwwroot \ Scriptにあります)には、次のコードが含まれています。
<%
response.write(Server.MapPath("test.asp") & "<br>")
response.write(Server.MapPath("script/test.asp") & "<br>")
response.write(Server.MapPath("/script/test.asp") & "<br>")
response.write(Server.MapPath("\script") & "<br>")
response.write(Server.MapPath("/") & "<br>")
response.write(Server.MapPath("\") & "<br>")
%>
Output:
c:\inetpub\wwwroot\script\test.asp
c:\inetpub\wwwroot\script\script\test.asp
c:\inetpub\wwwroot\script\test.asp
c:\inetpub\wwwroot\script
c:\inetpub\wwwroot
c:\inetpub\wwwroot
例2
相対パスを使用して、ブラウザーで表示されているページへの相対物理パスを返す方法:
<%
response.write(Server.MapPath("../"))
%>
or
<%
response.write(Server.MapPath("..\"))
%>
❮完全なサーバーオブジェクトリファレンス