Getting installation launch application installation folder using C #

There were several other similar messages, but I could not pinpoint the one that fully relates to my problem.

Simply put, my application exe file is in C:\MyApp\run.exe,

how can i find a programmed path search C:\MyApp

+5
source share
3 answers

Two of the answers given are correct, but rely on using Windows Forms. If this is not your cup of tea, there are alternatives.

Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)

and

Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
+4
source
using System.IO;
using System.Windows.Forms;

string appPath = Path.GetDirectoryName(Application.ExecutablePath);

UPDATE:

For a WPF application, you can use the following:

using System.Reflection;

string appPath = Assembly.GetExecutingAssembly().Location;
+8
source

Environment.CurrentDirectory - - , , .

0

All Articles