ASP.Net MapPath
Posted by cavemansblog on August 11, 2009
Writing code in a web application with not access to HttpContext and still need to map to a folder in the website? No problem.. you can use the System.Web.Hosting.HostingEnvironment.MapPath function.
//This is how you would map if you had access to the HttpContext object
System.Web.HttpContext.Current.Server.MapPath("~/App_Data/data.xml");
//and here is how you would map if you do not have access to the HttpContext object
System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/data.xml");
