how to get the application path ? bin path
in asp.net
thank's in advance
how to get the application path ? bin path
in asp.net
thank's in advance
Server.MapPath("~/bin")
You could also use the HostingEnvironment.ApplicationPhysicalPath property.
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");
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.
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
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