Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get the Path of Executable of my windows Application.
Should I use
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
or
Application.ExecutablePath ;

Which is best... ? Please Reply...
Posted
Comments
Maciej Los 30-Jul-13 3:58am    
WPF? WinForms?
Thomas Daniels 30-Jul-13 4:54am    
WinForms: in WPF there's no Application class. It's a part of the System.Windows.Forms namespace.
Maciej Los 30-Jul-13 4:59am    
I know it. Several times on this forum i've seen similar question... that's why i'm asking.
Sushil Mate 30-Jul-13 4:04am    
Application.ExecutablePath

First of all, please, read my comment.

The "best method" doesn't exists. It depends on your needs...

Read about the difference here:
HOW TO: Determine the Executing Application's Path[^]
Application.ExecutablePath Property [^]
Find the location of my application's executable in WPF (C# or vb.net)?[^]
 
Share this answer
 
v2
Comments
Sushil Mate 30-Jul-13 4:11am    
you don't answering question though? ;)
Maciej Los 30-Jul-13 4:51am    
Yes, it's because of my comment and other several reasons, for example:
1) i don't know what OP trying to achieve...
2) ExecutablePath returns the path for the executable file that started the application, including the executable name (not executable directory),
3) "best way" doesn't exists; this depends on needs (see point no. 1)
Maciej Los 30-Jul-13 5:02am    
I had updated my answer. Thank you form your comment.
Sushil Mate 30-Jul-13 5:11am    
Thanks for considering suggestion. it looks good now :)
Maciej Los 30-Jul-13 5:23am    
Thank you ;)
You will find the difference here: Best way to get application folder path[^]

I found the link using Google[^]. Do search on Google/Bing before you post. It will not only give you the answer in most cases but it will save you a lot of time.
 
Share this answer
 
Hi,
Application.ExecutablePath - This will be fine.

First use the namespace
C#
using System.IO;


To get the Executable Path
C#
string path = Path.GetDirectoryName(Application.ExecutablePath);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900