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
The first, is the directory of the executable of your application. Beware! It can be changed at runtime.
The second, will be the directory of the assembly (.dll) you run the code from.
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) ;
精彩评论