Not A Subscriber?
Join thousands of people who build and refuse to get left behind. One message a week on building, using AI as an accelerator, and staying sharp in the new AI frontier.
Receive one free message a weekApril 14, 2009 Donn Felker · updated July 5, 2013
Finding App_Data Programmatically
While writing some code I needed to be able to access the the App_Data directory in my ASPNET MVC app. Doing this usually involves a Server.MapPath, but this wont work for my unit test.
Here’s how you can get around it:
var appDataPath = (string)AppDomain.CurrentDomain.GetData(“DataDirectory”) ?? AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
Now I have my data directory for the test as well as during execution of the ASPNET MVC app.
During unit test execution it will be in testing directory while at runtime it will be in the ASPNET App_Data directory.