Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the Installation Folder of Running Application using C#

Tags:

c#

.net

There were several other similar posts, but I could not pinpoint one that relates entirely to my issue.

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

how can I find the programatically find the path C:\MyApp

like image 367
Shamim Hafiz - MSFT Avatar asked Jul 06 '11 13:07

Shamim Hafiz - MSFT


1 Answers

using System.IO;
using System.Windows.Forms;

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

UPDATE:

For a WPF application you could use the following:

using System.Reflection;

string appPath = Assembly.GetExecutingAssembly().Location;
like image 63
Jason Down Avatar answered Nov 14 '22 21:11

Jason Down