Tuesday, 21 December 2010

Server.MapPath when HttpContext is null

I've been writing some code that is fired from a scheduled task and need to access the root of a website. The usual method of Server.MapPath() returns an error as the HttpContext is null due to running under another thread.
To work around this problem you can use the method:
System.Web.Hosting.HostingEnvironment.MapPath()

1 comment:

Anonymous said...

Went from

Server.MapPath(....)

to

HttpContext.Server.MapPath(...)

to

your solution.

Success! Thanks!