• Published
  • 1 min

How to find Application root folder in Scheduled task (no HttpContext available)

In case you need a way to find the folder on the file system where your application runs when HttpContext is not available, you can use:

string applicationPhysicalPath =  HostingEnvironment.ApplicationPhysicalPath;

This is useful for instance when you are writing a sitemap generator and want to write the sitemap.xml to the application root, and the application root changes by each deploy to the server (version folders).