Brinkster Knowledge Base

KB Home   /  Support  /  Code Snippets  /   ASP MapPath example
ASP MapPath example Articles
Copy and paste this code snippet into your .asp page, then view the page in your web browser.
http://yoursite.com/page.asp
We suggest using mappath instead of using an absolute path in your coded applications.

*Note that no edit to the code needs to be made at all to run this demonstration.*

<html>
<head><title>ASP MapPath Demo</title></head>
<body>
<%
response.write "<font face='HELVETICA'>" &_
"<b>ASP Server.MapPath Demonstration</b><br><br>The &quot;File.txt&quot; file does not actually exist;"&_
"unless you created one that is, this is used as a demonstration of how to use mappath.<br>" &_
"For a more dramatic effect, place this file in a sub folder of your website's root folder.<br><br>" &_
"This path will take you to the folder this file is currently running in.<br>" &_
"<table border=0><tr><td><b>ASP Path:</b> &nbsp;&nbsp;&nbsp;&nbsp;</td><td>server.mappath (&quot;file.txt&quot;)</td></tr>" &_
"<tr><td><b>Output:</b></td><td> " & server.mappath("file.txt") & "</td></tr></table>" &_
"<br><br>" &_
"This path will take you to the root of your website, notice the use of the &quot;/&quot; at the beginning of the path.<br>" &_
"<table border=0><tr><td><b>ASP Path:</b> &nbsp;&nbsp;&nbsp;&nbsp;</td><td>server.mappath (&quot;/file.txt&quot;)</td></tr>" &_
"<tr><td><b>Output:</b></td><td> " & server.mappath("/file.txt") & "</td></tr></table>" &_
"<br><br>For a more detailed explanation of Server.MapPath please visit this <a style=text-decoration:none href='http://www.w3schools.com/ASP/met_mappath.asp'>Helpful Site</a>" &_
"</font>"
%>
</body>
</html>