Méthode MapPathASP


Server 对象参考手册Référence complète de l'objet Server

La méthode MapPath mappe le chemin spécifié vers le chemin physique correspondant sur le serveur.

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

Syntaxe

Server.MapPath(path)

Paramètre Description
path Obligatoire. Le chemin relatif ou absolu à mapper vers un chemin physique. Si le paramètre commence par / ou \, un chemin virtuel complet est renvoyé. Si le paramètre ne commence pas par / ou \, le chemin relatif au fichier .asp en cours de traitement est renvoyé.

Exemples

Exemple 1

Par exemple, 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.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>")
%>

Sortie :

c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscriptscripttest.html
c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscript
c:inetpubwwwroot
c:inetpubwwwroot

Exemple 2

Comment utiliser un chemin relatif pour renvoyer le chemin physique relatif à la page consultée dans le navigateur :

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

Ou :

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


Server 对象参考手册Référence complète de l'objet Server Autres extensions