Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I'm making an application that needs access to application directory at runtime.
How do i get it??
Posted

This is the precise Answer:

string exeDirectory = System.IO.Path.GetDirectory(
    System.Reflection.Assembly.GetEntryAssembly().Location);


There are few other methods, they are all inaccurate: some depend on the hosting of the application, some depend on where you call it. This method, more exactly, gives you the location of the main executable module of the entry assembly of the currently calling code. Many also use GetCallingAssembly, and that creates instability as you can always move calling method from one assembly to another.

Also, don't use CurrentDirectory. This is very important. This directory really depends on how the user starts the application (the user can start it from anywhere), and this directory can change during run time.

—SA
 
Share this answer
 
v3
There are some side issues with some of the System.Environment solutions to retrieving this data. I blogged about the sure-fire way to get the path information that works, even if your WPF application is launched from a COM application (which screws up the base implementations).

You can find details here[^].
 
Share this answer
 
Environment object will give you the details you looking for.

C#
Environment.CurrentDirectory


Mark it as answer if it is helpful
 
Share this answer
 
v2

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