Hi,
What is work of Server.MapPah method in ASP.NET?
Thanks.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Anuja PawarPosted Dec 27, 2011, 7:02 AM
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.
Satyapriya NayakPosted Dec 24, 2011, 2:03 AM
Each file on a Web server has two ways of being accessed - through a virtual path and through a physical path
We use Server.MapPath to obtain the physical path of a particular directory.
Please refer the below links
http://www.4guysfromrolla.com/webtech/121799-1.shtml
http://www.c-sharpcorner.com/uploadfile/abhikumarvatsa/server-mappath-in-Asp-Net/
Thanks
Vikrant JadhavPosted Dec 24, 2011, 1:04 AM
Thanks & Regards,
Vikrant Jadhav
If This help you then Mark as a "Correct Answer".