ASP MapPathメソッド
完全な Server オブジェクトリファレンスマニュアル
MapPath メソッドは、指定されたパスをサーバー上の対応する物理パスにマップします。
注意:このメソッドは Session.OnEnd および Application.OnEnd では使用できません。
構文
Server.MapPath(path)
| パラメータ | 説明 |
|---|---|
| path | 必須。物理パスにマップされる相対パスまたは絶対パス。このパラメータが / または \ で始まる場合は、完全な仮想パスを返します。このパラメータが / または \ で始まらない場合は、処理中の .asp ファイルからの相対パスを返します。 |
例
例 1
例として、ファイル test.asp は C:\Inetpub\wwwroot\Script にあります。
ファイル Test.asp (C:\Inetpub\wwwroot\Script にあります) には次のコードが含まれています:
<%
response.write(Server.MapPath("test.html") & "<br>")
response.write(Server.MapPath("script/test.html") & "<br>")
response.write(Server.MapPath("/script/test.html") & "<br>")
response.write(Server.MapPath("script") & "<br>")
response.write(Server.MapPath("/") & "<br>")
response.write(Server.MapPath("") & "<br>")
%>
出力:
c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscriptscripttest.html
c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscript
c:inetpubwwwroot
c:inetpubwwwroot
response.write(Server.MapPath("test.html") & "<br>")
response.write(Server.MapPath("script/test.html") & "<br>")
response.write(Server.MapPath("/script/test.html") & "<br>")
response.write(Server.MapPath("script") & "<br>")
response.write(Server.MapPath("/") & "<br>")
response.write(Server.MapPath("") & "<br>")
%>
出力:
c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscriptscripttest.html
c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscript
c:inetpubwwwroot
c:inetpubwwwroot
例 2
相対パスを使用して、ブラウザで表示中のページに到達する相対物理パスを返す方法:
<%
response.write(Server.MapPath("../"))
%>
または:
<%
response.write(Server.MapPath(".."))
%>
response.write(Server.MapPath("../"))
%>
または:
<%
response.write(Server.MapPath(".."))
%>
完全な Server オブジェクトリファレンスマニュアル その他の拡張