Retrieving the Directory of the Current Application

Very often I need to find the directory where the executable file is located.  You can use reflection to obtain the path with the following line of code.

string templateBaseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Remove(0, 6);

Note that you need to remove the first 6 characters if you don't want the "file:/"  prefix in your path.

Happy Coding!