TIP: Getting the Base Directory of where your App is Running
Need your app's running directory in .NET? Use AppDomain.CurrentDomain.BaseDirectory, which works for both web and non-web projects.
Note: I posted this quite awhile back at FooTheory but it didn’t transfer over to this blog via cross posting for some reason. Internet-wackiness I call it.
This is an oldie but a goodie. It was brought up that not one developer at my current client knew about this object in the framework.
So, how do you find where the app is running at?
Easy: Use the AppDomain object. This works for both Web and Non-Web projects.
Code:
1 AppDomain.CurrentDomain.BaseDirectoryThe AppDomain object will return the application’s domain information, which includes the info about where it is executing. We get the current domain of the executing thread and then get its BaseDirectory to see where it’s executing.
This:
Returns this:
Enjoy.



