1

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?

Guru Stron
  • 102,774
  • 10
  • 95
  • 132
Leen Hatem
  • 11
  • 2
  • It is worth noting that .net 4.5.2 is End Of Life, as of April 2022. You should strongly consider upgrading. – David L Feb 08 '23 at 17:48
  • This may help https://stackoverflow.com/questions/837488/how-can-i-get-the-applications-path-in-a-net-console-application – Serg Feb 08 '23 at 18:04

1 Answers1

1

try AppDomain.BaseDirectory()

String _path = System.AppDomain.CurrentDomain.BaseDirectory;
Hossein Sabziani
  • 1
  • 2
  • 15
  • 20