We have a web application written in ASP.NET 3.5. In it, we access a file in the code-behind. (Ordinary C# file access, done on the server during the page life-cycle, this
In code behind: HttpContext.Current.Server.MapPath("~")
Use:
Server.MapPath("~");
To get the path of the root of the application:
//equivalent to Server.MapPath("/"); if at domain root, e.g Http://mysite.com/
string path = Server.MapPath("~");
This answer gives a rundown of a few different common Server.MapPath()
uses that may also be of use to you.