Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Application.ExecutablePath on WPF Framework 3.5

This line is fine in a WinForm Framework3.5 but not in a WPF Framework3.5.

Path.GetDirectoryName(Application.ExecutablePath); 

How can I get the exe path on a WPF app ?

like image 579
Fred Smith Avatar asked Dec 06 '22 06:12

Fred Smith


2 Answers

There are several ways to get exe path. Try the next:

  • Application.StartupPath
  • Path.GetDirectoryName(Environment.GetCommandLineArgs()[0])
  • Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)
  • Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
  • System.Reflection.Assembly.GetEntryAssembly().Location
like image 165
Dzmitry Martavoi Avatar answered Dec 08 '22 21:12

Dzmitry Martavoi


Try this:

System.IO.Path.GetDirectoryName( 
  System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );
like image 39
NeddySpaghetti Avatar answered Dec 08 '22 20:12

NeddySpaghetti