Reputation: 16903
How can I get runnig path of my application from app.xaml.cs itself?
Upvotes: 3
Views: 6517
Reputation: 1439
This always works:
System.Windows.Forms.Application.StartupPath
Upvotes: 0
Reputation: 2307
You could try
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
AppDomain.CurrentDomain.BaseDirectory
and/or
Environment.CurrentDirectory
Upvotes: 11
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