Fred Smith
Fred Smith

Reputation: 2129

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 ?

Upvotes: 4

Views: 12577

Answers (3)

martavoi
martavoi

Reputation: 7092

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

Upvotes: 12

Joe Sonderegger
Joe Sonderegger

Reputation: 804

You can unpack a Uri like this:

string codeBase = Assembly.GetExecutingAssembly().CodeBase;
   UriBuilder uri = new UriBuilder(codeBase);
   string path = Uri.UnescapeDataString(uri.Path);

Upvotes: 1

NeddySpaghetti
NeddySpaghetti

Reputation: 13495

Try this:

System.IO.Path.GetDirectoryName( 
  System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );

Upvotes: 2

Related Questions