Metoda ASP MapPath
❮ Kompletní Reference Server Object Reference
Metoda MapPath mapuje zadanou cestu na fyzickou cestu.
Poznámka: Tuto metodu nelze použít v Session.OnEnd a Application.OnEnd.
Syntax
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 |
Příklady
Příklad 1
V příkladu níže je soubor "test.asp" umístěn v C:\Inetpub\Wwwroot\Script.
Soubor "test.asp" (umístěný v C:\Inetpub\Wwwroot\Script) obsahuje následující kód:
<%
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
Příklad 2
Jak použít relativní cestu k vrácení relativní fyzické cesty ke stránce, která je zobrazena v prohlížeči:
<%
response.write(Server.MapPath("../"))
%>
or
<%
response.write(Server.MapPath("..\"))
%>
❮ Kompletní Reference Server Object Reference