开发者

get path for my .exe [duplicate]

开发者 https://www.devze.com 2023-01-21 15:08 出处:网络
This question already has answers here: How can I get the application's path in a .NET console application?
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

精彩评论

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