开发者

get path for my .exe [duplicate]

This question already has answers here: How can I get the application's path in a .NET console application? (30 answers) 开发者_如何学JAVA Closed 8 years ago.

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) ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜