I have a web project like:
namespace Web
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, Event
In case you want a solution that works for WinForms and Web Apps
public string ApplicationPath
{
get
{
if (String.IsNullOrEmpty(AppDomain.CurrentDomain.RelativeSearchPath))
{
return AppDomain.CurrentDomain.BaseDirectory; //exe folder for WinForms, Consoles, Windows Services
}
else
{
return AppDomain.CurrentDomain.RelativeSearchPath; //bin folder for Web Apps
}
}
}
Above solution code snippet is for binaries locations
The AppDomain.CurrentDomain.BaseDirectory is still valid path for Web Apps, it's just a root folder where the web.config and Global.asax and is same as Server.MapPath(@"~\");