طريقة ASP MapPath
❮ مرجع كائن الخادم الكامل
تقوم طريقة MapPath بتعيين مسار محدد إلى مسار مادي.
ملاحظة: لا يمكن استخدام هذه الطريقة في Session.OnEnd و Application.OnEnd.
بناء الجملة
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 |
أمثلة
مثال 1
على سبيل المثال أدناه ، يوجد الملف "test.asp" في C: \ Inetpub \ Wwwroot \ Script.
يحتوي الملف "test.asp" (الموجود في C: \ Inetpub \ Wwwroot \ Script) على التعليمات البرمجية التالية:
<%
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
مثال 2
كيفية استخدام مسار نسبي لإرجاع المسار المادي النسبي إلى الصفحة التي يتم عرضها في المستعرض:
<%
response.write(Server.MapPath("../"))
%>
or
<%
response.write(Server.MapPath("..\"))
%>
❮ مرجع كائن الخادم الكامل