Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the application path in asp.net?

Tags:

c#

asp.net

how to get the application path ? bin path

in asp.net

thank's in advance

like image 417
Gold Avatar asked Nov 28 '10 19:11

Gold


People also ask

How to get physical application path in c#?

Solution 4. string path=Server. MapPath("~/Report/rpt/ReportSchema. xsd");

What is the application path?

A program's App Paths key typically contains a value named Path, which should contain a semicolon-delimited list of directories where the program's . dll files could be located. Windows uses this key to find your application and its . dll files if their locations are not already in the system's path.


7 Answers

Server.MapPath("~/bin")

You could also use the HostingEnvironment.ApplicationPhysicalPath property.

like image 83
Darin Dimitrov Avatar answered Oct 05 '22 14:10

Darin Dimitrov


Gets the ASP.NET application's virtual application root path on the server.

Request.ApplicationPath;

http://msdn.microsoft.com/en-us/library/system.web.httprequest.applicationpath.aspx

ResolveUrl("~/bin");
like image 23
hunter Avatar answered Oct 05 '22 15:10

hunter


I needed this at app_start where there's not yet an HttpContext, thus Request and Server are not options.

This did the trick:

System.Web.HttpRuntime.BinDirectory

Edit

As of .net core, you can use PlatformServices.Default.Application.ApplicationBasePath of nuget pkg Microsoft.Extensions.PlatformAbstractions, which resolves for any runtime.

like image 23
jenson-button-event Avatar answered Oct 05 '22 15:10

jenson-button-event


HttpContext.Current.Server.MapPath("~/bin") ;
Application.StartupPath + "/bin";
AppDomain.CurrentDomain.BaseDirectory + "/bin";

//Note in Asp.net Core its little bit different
public class ValuesController : ControllerBase
{
        IHostingEnvironment _hostingEnvironment;
        public ValuesController(IHostingEnvironment hostingEnvironment)
        {
            _hostingEnvironment = hostingEnvironment;
            string applicationPath = _hostingEnvironment.ContentRootPath;
            string wwwrootPath = _hostingEnvironment.WebRootPath;
        }
}

and many more that described in a blog

like image 38
Raj kumar Avatar answered Oct 05 '22 16:10

Raj kumar


Using the following snippet:

string strPath = HttpContext.Current.Server.MapPath("~/bin");
like image 25
Sutirth Avatar answered Oct 05 '22 15:10

Sutirth


Server.MapPath("~/bin")

You can also use Request.PhysicalApplicationPath

like image 45
Vishal Gavle Avatar answered Oct 05 '22 15:10

Vishal Gavle


HostingEnvironment.MapPath() Vs Server.MapPath() Server.MapPath is used to map a physical location on webserver for asp.net. String path = HttpContext.Current.Server.MapPath("~/myFolder/myFile.txt"); Server.MapPath specifies the relative or virtual path to map to a physical directory.

sample:

 string path=System.Web.Hosting.HostingEnvironment.MapPath(@"~/Files/ExamResult.rdlc");

For More Detail Visit This Link

like image 22
Amin Golmahalle Avatar answered Oct 05 '22 15:10

Amin Golmahalle