0

How can I make a string variable containing path to my win-app executable folder? I know that there's the simple command Application.ExecutablePath which returns all the path including the .exe name, but I need that path without the .exe name.

2
  • What language is this?
    – Marckvdv
    Commented Jan 3, 2014 at 19:27
  • I'm using c# language Commented Jan 3, 2014 at 19:32

2 Answers 2

3

You want System.IO.Path.GetDirectoryName:

string appPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
0
0

@shf301's answer works for Windows Forms apps. The generic way that should work for any executable (*.exe), whether it's a Windows Forms or not is

string fqn = System.Reflection.Assembly.GetEntryAssembly().Location ;
string dir = Path.GetDirectoryName(fqn) ;

Or even easier:

string baseDir = AppDomain.CurrentDomain.BaseDirectory ;

AppDomain.BaseDirectory returns "the base directory that the assembly resolver uses to probe for assemblies." For ordinary executables, that's the directory containing the entrypoint assembly.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.