Leen Hatem
Leen Hatem

Reputation: 11

how to get the installation path in C#?

I am modifying a .NET v4.5.2 code, and I want to be able to get a script path from the installation folder (so when a user install the app, the app is able to access and run the script)

I tried Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) method but it returned the wrong value (it returned the path: "C:\Users\HP\AppData\Roaming" , whereas my program location (after installation) is "C:\Program Files (x86)". I also tried Environment.GetCommandLineArgs()[0] and Path.GetDirectoryName(appFileName) but they returned the location of the file where the code was written. could you please help me?

Upvotes: 1

Views: 157

Answers (1)

Hossein Sabziani
Hossein Sabziani

Reputation: 3485

try AppDomain.BaseDirectory()

String _path = System.AppDomain.CurrentDomain.BaseDirectory;

Upvotes: 1

Related Questions