Try this. Don't forget using System.Reflection
.
string baseDir = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
I tried this:
label1.Content = Directory.GetCurrentDirectory();
and get also the directory.
String exePath = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
string dir = Path.GetDirectoryName(exePath);
Try this!
You can also use freely Application.StartupPath from System.Windows.Forms, but you must to add reference for System.Windows.Forms assembly!
You can also use the first argument of the command line arguments:
String exePath = System.Environment.GetCommandLineArgs()[0]
I used simply string baseDir = Environment.CurrentDirectory;
and its work for me.
Good Luck
Edit:
I used to delete this type of mistake but i prefer to edit it because i think the minus point on this answer help people to know about wrong way. :) I understood the above solution is not useful and i changed it to string appBaseDir = System.AppDomain.CurrentDomain.BaseDirectory;
Other ways to get it are:
1. string baseDir =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
2. String exePath = System.Environment.GetCommandLineArgs()[0];
3. string appBaseDir = System.IO.Path.GetDirectoryName
(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Good Luck
Here is another:
System.Reflection.Assembly.GetExecutingAssembly().Location
Source: Stackoverflow.com