← All articles

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.

Donn Felker

Donn Felker

2008.03.23 · 1 min read

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.BaseDirectory

The 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:

image

Returns this:

image

Enjoy.

Donn Felker

Written by Donn Felker

I've spent 25+ years shipping software, writing books, and running my own companies. I write about thinking clearly, working for yourself, and doing real work while AI rewrites the rules. New essays land here every week.

Get the newsletter

Keep reading