36

how to get the application path ? bin path

in asp.net

thank's in advance

Gold
  • 54,738
  • 95
  • 206
  • 310
  • Related post [here](https://stackoverflow.com/q/10951599/465053). – RBT Nov 14 '17 at 10:30
  • Another post which talks about [server map paths in web applications in .Net](https://stackoverflow.com/q/275781/465053) – RBT Nov 14 '17 at 10:35

7 Answers7

39
Server.MapPath("~/bin")

You could also use the HostingEnvironment.ApplicationPhysicalPath property.

Darin Dimitrov
  • 960,118
  • 257
  • 3,196
  • 2,876
30

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");
hunter
  • 58,834
  • 17
  • 108
  • 112
19

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
jenson-button-event
  • 15,947
  • 8
  • 73
  • 144
16
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

Raj kumar
  • 995
  • 11
  • 17
13

Using the following snippet:

string strPath = HttpContext.Current.Server.MapPath("~/bin");
Carsten
  • 10,430
  • 7
  • 37
  • 58
Sutirth
  • 894
  • 10
  • 14
4
Server.MapPath("~/bin")

You can also use Request.PhysicalApplicationPath

Vishal Gavle
  • 369
  • 2
  • 5
2

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

AminGolmahalle
  • 2,077
  • 2
  • 16
  • 23