Find the location of my application's executable in WPF (C# or vb.net)?

How can I find the location of my application's executable in WPF (C# or VB.Net)?

I've used this code with windows forms:

Application.ExecutablePath.ToString();

But with WPF I received this error from Visual Studio:

System.Window.Application does not contain a definition for ExecutablePath.


Solution 1:

System.Reflection.Assembly.GetExecutingAssembly().Location should work.

Solution 2:

Several alternatives:

Directory.GetParent(Assembly.GetExecutingAssembly().Location)

System.AppDomain.CurrentDomain.BaseDirectory

Only in VB:

My.Application.Info.DirectoryPath

Solution 3:

this is useful for you: Application.ExecutablePath equals to:

Process.GetCurrentProcess().MainModule.FileName;

Solution 4:

Environment.CurrentDirectory returns parent directory of exe file