2

What is the difference between the magic paths in these namespaces:

Environment.SpecialFolder.LocalApplicationData

versus

Application.LocalUserAppDataPath

And

Environment.SpecialFolder.ApplicationData

versus

Application.CommonAppDataPath

etc...

Yousha Aleayoub
  • 4,532
  • 4
  • 53
  • 64
Jake
  • 11,273
  • 21
  • 90
  • 147
  • 1
    Which is the ***namespace*** of _`Application`_ ? – Kiquenet Mar 14 '17 at 10:28
  • @Kiquenet `System.Windows.Forms` and that's the difference... – Yousha Aleayoub May 17 '20 at 13:36
  • 1
    Does this answer your question? [Difference between 'SpecialFolder.LocalApplicationData' and 'SpecialFolder.ApplicationData'?](https://stackoverflow.com/questions/9709269/difference-between-specialfolder-localapplicationdata-and-specialfolder-appli) – Yousha Aleayoub May 17 '20 at 13:41

3 Answers3

5

On Windows 7:

Environment.SpecialFolder.LocalApplicationData = C:\Users\username\AppData\Local
Application.LocalUserAppDataPath = C:\Users\username\AppData\Local
Environment.SpecialFolder.ApplicationData = C:\Users\username\AppData\Roaming
Application.CommonAppDataPath = C:\Users\username\AppData\Roaming

Local is only ever stored on the local machine. Roaming is copied to the domain server (when in a domain) and is then loaded back onto other machines in that domain when you log on.

Polynomial
  • 27,674
  • 12
  • 80
  • 107
  • So they are the same? Why have two references to the same paths? And why is CommonAppDataPath under username? – Jake Dec 03 '11 at 17:51
  • 1
    @Jake - Because not all windows operating systems mean that these are the same. And future ones are not guaranteed to be the same either. You _do_ want your code to work on multiple systems, right? – Oded Dec 03 '11 at 17:55
  • @Jake - Apologies for the delay in explanation, I had an edit ready but my battery died last night. I've now applied that edit, so hopefully that'll explain a little better. – Polynomial Dec 04 '11 at 11:42
5

They are not the same. The Application version of them is aware of ClickOnce deployment, adjusting the paths accordingly to keep them isolated.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Which is the safer or more common choice for the average C# application targeting the average user: `Environment.SpecialFolder` or `Application` ? – Dan W Nov 28 '18 at 06:06
0

To add to the answer for anyone in the future who lands on this page, for all special folder related questions see the Microsoft's documentation which lists all the folder types:

Environment.SpecialFolder Enum

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122