This is the precise Answer:
string exeDirectory = System.IO.Path.GetDirectory(
System.Reflection.Assembly.GetEntryAssembly().Location);
There are few other methods, they are all inaccurate: some depend on the hosting of the application, some depend on where you call it. This method, more exactly, gives you the location of the main executable module of the entry assembly of the currently calling code. Many also use
GetCallingAssembly
, and that creates instability as you can always move calling method from one assembly to another.
Also, don't use
CurrentDirectory
. This is very important. This directory really depends on how the user starts the application (the user can start it from anywhere), and this directory can change during run time.
—SA