In ASP.NET how you get the physcial file path when HttpContext.Current is NULL?

John picture John · Sep 20, 2008 · Viewed 7.9k times · Source

I'm working with DotNetNuke's scheduler to schedule tasks and I'm looking to get the physical file path of a email template that I created. The problem is that HttpContext is NULL because the scheduled task is on a different thread and there is not http request. How would you go about getting the file's physical path?

Answer

bdukes picture bdukes · Sep 22, 2008

System.Web.Hosting.HostingEnvironment.MapPath is what you're looking for. Whenever you're using the Server or HttpContext.Current objects, check first to see if HostingEnvironment has what you need.