How To Get The Episerver App_data Folder Paths Location In Code

If you need to write an initialization module or you're writing some code to automate your continuous integration process, it's very likely you may need to get the file path where your App_data folder lives on your server.  Luckily, this is pretty easy using this snippet

 EPiServer.Framework.Configuration.EPiServerFrameworkSection.Instance.AppData.BasePath

As you can see, getting the base path out of Episerver is easy, however, on a lot of projects, the basepath might be set like this:

  <appData basePath="App_Data" />
  

If you try and run File.Exists() on this value it will obviously fail. Adding file paths into a web.config and checking that into source control isn't ideal, as every developer will likely have the website installed in different locations. Instead, I'd recommend using a method like this:

            var appDataBasePath = EPiServer.Framework.Configuration.EPiServerFrameworkSection.Instance.AppData.BasePath;

            if (appDataBasePath.ToLower() == "app_data") 
{
addDataBasePath = $@"{AppDomain.CurrentDomain.BaseDirectory}{appDataBasePath}";
            }

Enjoy!

submit to reddit

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

Back to top