4

I am currently trying to use the following to access a computer's local AppData folder:

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

This returns something along the lines of C:\\Users\\[USERNAME]\\AppData\\Roaming. What I want is to get the default AppData folder, as opposed to any specific user's folder.

I can hard code this C:\Users\Default\AppData\Local, but I'd feel more comfortable if there was a function that provided what I'm looking for.

Is there such a function, and if so, what is it?

mastur cheef
  • 185
  • 1
  • 3
  • 15

1 Answers1

4

I believe SpecialFolder.CommonApplicationData will get what you need.

From the MSDN documentation:

The directory that serves as a common repository for application-specific data that is used by all users.

JDB
  • 25,172
  • 5
  • 72
  • 123
  • Not what I was originally looking for, but I can now see that this is a better solution. Thank you. – mastur cheef Sep 30 '13 at 20:54
  • To make it more clear, `CommonApplicationData` resolves to `C:\ProgramData`, not to`C:\Users\Default\AppData\Local` – yurislav Apr 01 '19 at 08:12
  • Thanks @yurislav, but I think the idea is that the exact path is platform- and/or configuration-dependent. It can vary from machine to machine, but if you use this constant then your files will end up where they're supposed to be. – JDB Apr 08 '19 at 15:24