You can try the following
var path = (System.Web.HttpContext.Current == null)
? System.Web.Hosting.HostingEnvironment.MapPath("~/")
: System.Web.HttpContext.Current.Server.MapPath("~/");
which uses the hostingenvironment to get the path of the executing application.