If you need to write an Episerver initialization module, or you are writing some code to automate your continuous integration process, it is very likely you will need to get the folder path of your websites App_data folder in code. Luckily, this is pretty easy and can be done using this snippet of code:

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

If you try and run File.Exists() on this value, the request will obviously fail. Adding file paths into a web.config and checking that into source control isn't ideal. As every environment will have the website installed in different folder locations, you do not want to hardcode a server path like this. Instead, a better approach that I recommend is to use the following code snippet:

Enjoy! Happy Coding 🤘