Codefixer - ASP tutorials, resources and software
ASP.NET 3.5 Hosting – Click Here!
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Friday 9 May
MembersPro PayPal - ASP Membership software

ASP.NET 3.5 Hosting – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Server.Mappath - Using the ASP Server Object's Mappath Method

When you need to connect to a database or a file from your webpage you’ll need to know the exact file path to that particular datasource.
If you aren’t sure of the exact physical path then you can use Server.Mappath. Server.Mappath takes a path as a parameter and returns the exact physical location of that file on the hard drive.

For the examples below, the database “mydatabase.mdb” is located in the c:\inetpub\wwwroot\database directory. The c:\inetpub\wwwroot directory is set as the web root directory.

Our script uses the slash character to specify that the path returned should treated as a complete virtual path on the server and mapped from the root folder.

<%= Server.MapPath("/database/mydatabase.mdb")%>

This script outputs the following:

c:\inetpub\wwwroot\database\mydatabase.mdb

Because the path parameters in the following example does not start with a slash character, it is mapped relative to it's current directory, in this case c:\inetpub\wwwroot\database.


<%= Server.MapPath("mydatabase.mdb")%>

This script outputs the following:

c:\inetpub\wwwroot\database\mydatabase.mdb

So in a nutshell the MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.

Previous: Returning a Recordcount of -1
LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software