[Assuming you mean the bin folder] This is how I do it.
If your environment is typically Windows apps and Asp.Net, then you should:
- Check to see if
AppDomain.CurrentDomain.SetupInformation.PrivateBinPath
is not empty or null.
- If not, then check to see if it is rooted or not
- If not, then remember this value as
BinPath
(it ll be bin in Asp.Net) - but beware that more custom AppDomain hosting environments might have more than one path here and could have a rooted path.
Then, either
- It s
AppDomain.CurrentDomain.BaseDirectory
- Or
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, BinPath)
(where BinPath
is remembered from earlier).
There are some other advanced scenarios with this - Test Runners hosting a temporary domain for unit tests, and other strange things. Asp.Net also has it s dynamic folder which has been mentioned elsewhere on this answer - but that s a red-herring if you re just looking to get at the bin folder reliably.
You certainly can t just use the Entry Assembly s path - because in an Asp.Net site that will be dynamically generated and will reside in that dynamic folder.
Equally - there are things like Sql Server-hosted domains to consider, which changes the ballgame again (in this case you d get the MSSQL Server folder).
So any solution that can reliably determine this for any AppDomain is actually going to be best produced by trial and error I m afriad - until somebody comes up with a complete answer for every hosting scenario! So stick with your most common ones.