This question already has an answer here:
how can I get my .exe path because if I copy my .exe I can get my new path ?
System.Reflection.Assembly.GetEntryAssembly().Location;
In addition:
AppDomain.CurrentDomain.BaseDirectory
Assembly.GetEntryAssembly().Location
Assembly.GetEntryAssembly().Location
works for me. The first one has file;\
while the second one provides the absolute file path of the executing .exe. Add System.IO.Path.GetDirectoryName()
to get the path only - CraftedGaming
In a Windows Forms project:
For the full path (filename included): string exePath = Application.ExecutablePath;
For the path only: string appPath = Application.StartupPath;
in visualstudio 2008 you could use this code :
var _assembly = System.Reflection.Assembly
.GetExecutingAssembly().GetName().CodeBase;
var _path = System.IO.Path.GetDirectoryName(_assembly) ;
System.IO.Path.GetDirectoryName
- benderto
AppDomain.CurrentDomain.BaseDirectory
- user799821Path.GetDirectoryName
to get the folder without the filename. - ProfKSystem.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
- SnookerC