Metode Jalur Peta ASP
Referensi Objek Server Lengkap
Metode MapPath memetakan jalur tertentu ke jalur fisik.
Catatan: Metode ini tidak dapat digunakan di Session.OnEnd dan Application.OnEnd.
Sintaksis
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 |
Contoh
Contoh 1
Untuk contoh di bawah ini, file "test.asp" terletak di C:\Inetpub\Wwwroot\Script.
File "test.asp" (terletak di C:\Inetpub\Wwwroot\Script) berisi kode berikut:
<%
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
Contoh 2
Cara menggunakan jalur relatif untuk mengembalikan jalur fisik relatif ke halaman yang sedang dilihat di browser:
<%
response.write(Server.MapPath("../"))
%>
or
<%
response.write(Server.MapPath("..\"))
%>
Referensi Objek Server Lengkap