Méthode ASP MapPath


❮ Référence complète de l'objet serveur

La méthode MapPath mappe un chemin spécifié à un chemin physique.

Remarque : Cette méthode ne peut pas être utilisée dans Session.OnEnd et Application.OnEnd.

Syntaxe

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

Exemples

Exemple 1

Pour l'exemple ci-dessous, le fichier "test.asp" se trouve dans C:\Inetpub\Wwwroot\Script.

Le fichier "test.asp" (situé dans C:\Inetpub\Wwwroot\Script) contient le code suivant :

<%
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

Exemple 2

Comment utiliser un chemin relatif pour renvoyer le chemin physique relatif vers la page qui est affichée dans le navigateur :

<%
response.write(Server.MapPath("../"))
%>

or

<%
response.write(Server.MapPath("..\"))
%>

❮ Référence complète de l'objet serveur