Getting the actual executable directory comes handy when you need to execute the program remotely (e.g. from STAF). The execution directory is then different than the actual executable (*.exe) location. With the tricks below you need to create a *.log file near the (*.exe) file:
Console.WriteLine(Application.StartupPath);
Console.WriteLine(Path.GetDirectoryName(Application.ExecutablePath));
Console.WriteLine(Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Program)).CodeBase));
Console.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().Location);
Console.WriteLine(System.IO.Path.GetDirectoryName(Application.ExecutablePath));
These all return the actual executable directory path.
Thanks - a quick google search turned this up and it was what I was looking for.
ReplyDeleteVery helpful. Thanks. ;)
ReplyDeleteReference System.Windows.Forms for the Application object to be found. This is mostly for a Console application or a non-Windows.Forms program.
ReplyDeleteThank you. Clear and short. Very useful.
ReplyDelete