6

In C#, how do I refer the following locations rather than hard-coding them?

  • Program Files (x86)
  • Program Files
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Nemo
  • 4,601
  • 11
  • 43
  • 46

1 Answers1

13

You can use:

System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles);

to get the program files folder on the machine. This will return whatever is correct for the application that is running. So for 32-bit applications on a 64-bit machine, it will return "C:\Program Files (x86)" on a English version of Windows.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Simon P Stevens
  • 27,303
  • 5
  • 81
  • 107