Sauron
Sauron

Reputation: 16903

Get the Application Running Path in App.xaml.cs

How can I get runnig path of my application from app.xaml.cs itself?

Upvotes: 3

Views: 6517

Answers (3)

Paul Coldrey
Paul Coldrey

Reputation: 1439

This always works:

System.Windows.Forms.Application.StartupPath

Upvotes: 0

Mihai Lazar
Mihai Lazar

Reputation: 2307

You could try

Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

AppDomain.CurrentDomain.BaseDirectory

and/or

Environment.CurrentDirectory

Upvotes: 11

Matt Hamilton
Matt Hamilton

Reputation: 204199

You can just use the System.Environment.GetCommandLineArgs property to get the command line that started the application. Parse that with the System.IO.Path methods to extract just the executable's filename or full path.

var exeName = System.IO.Path.GetFileName(
    System.Environment.GetCommandLineArgs()[0]);
MessageBox.Show("This exe's filename is " + exeName);

Upvotes: 1

Related Questions