Cannot use Server.MapPath
Solution 1:
you can try using this
System.Web.HttpContext.Current.Server.MapPath(path);
or use HostingEnvironment.MapPath
System.Web.Hosting.HostingEnvironment.MapPath(path);
Solution 2:
Your project needs to reference assembly System.Web.dll
. Server is an object of type HttpServerUtility
. Example:
HttpContext.Current.Server.MapPath(path);
Solution 3:
System.Web.HttpContext.Current.Server.MapPath("~/")
gives null if we call it from a thread.
So, Try to use
System.Web.Hosting.HostingEnvironment.MapPath("~/")
Solution 4:
Firt add a reference to System.web
, if you don't have. Do that in the References folder.
You can then use Hosting.HostingEnvironment.MapPath(path);