Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server.Mappath in C# classlibrary

How can i use the server.mappath method in a C# class library class ,which acts as my BusinessLayer for My ASP.NET WEbsite

like image 920
Shyju Avatar asked Jul 29 '09 11:07

Shyju


People also ask

What is Server MapPath?

The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server.

How do I use MapPath?

If the path starts with either a forward slash(/) or backward slash(\) the MapPath Method returns a path as if the path is a full virtual path. If the path doesn't start with a slash, the MapPath Method returns a path relative to a directory of the . asp file being processed.

What is virtual path and physical path in asp net?

Physical path - This is the actual path the file is located by IIS. Virtual path - This is the logical path to access the file which is pointed to from outside of the IIS application folder.


2 Answers

By calling it?

var path = System.Web.HttpContext.Current.Server.MapPath("default.aspx"); 

Make sure you add a reference to the System.Web assembly.

like image 127
Aaron Powell Avatar answered Sep 21 '22 20:09

Aaron Powell


You can get the base path by using the following code and append your needed path with that.

string  path = System.AppDomain.CurrentDomain.BaseDirectory; 
like image 42
Elanchezhian Narayanasamy Avatar answered Sep 20 '22 20:09

Elanchezhian Narayanasamy