how to get the application path ? bin path
in asp.net
thank's in advance
Solution 4. string path=Server. MapPath("~/Report/rpt/ReportSchema. xsd");
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.
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
Using the following snippet:
string strPath = HttpContext.Current.Server.MapPath("~/bin");
                        Server.MapPath("~/bin")
You can also use 
Request.PhysicalApplicationPath
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With