7

I have a WPF application that must run for all users of a machine with the same settings. The settings must be read/write. I have previously been storing user configuration settings in CommonApplicationData, for example

var settingsFile = Path.Combine(Environment.GetFolderPath(
  Environment.SpecialFolder.CommonApplicationData),
    "[company]", "[product]", "settings.xml");

However I read this morning that CommonApplicationData is used for roaming profiles, meaning they are not machine specific. From what I can find, we have the following options for application data (source):

// Store application-specific data for the current roaming user.
// A roaming user works on more than one computer on a network.
// A roaming user's profile is kept on a server on the network and is loaded onto a system ' when the user logs on.
System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);


// Store in-common application-specific data that is used by all users.
System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);


// Store application-specific data that is used by the current, non-roaming user.
System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

To summarize, the options are

  • Single user, roaming
  • All users, roaming
  • Single user, non-roaming

What I need is all users, non-roaming. My initial thought is to chuck it all into the install folder, but that seems a little old-school?

Thoughts?

Martin Doms
  • 8,598
  • 11
  • 43
  • 60
  • 1
    Where did you read that `CommonApplicationData` is roaming? I find it a bit strange... – Anders Abel Dec 06 '11 at 20:54
  • I read it in Bill Wagner's book Effective C#. However that's the only place I can find this tidbit so maybe it's a rare mistake on Wagner's part, and I'd be very interested in hearing if I'm wrong about this. – Martin Doms Dec 06 '11 at 20:56
  • From the [MSDN](http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx) documentation: "The directory that serves as a common repository for application-specific data that is used by all users." – Paul Ruane Dec 06 '11 at 21:06
  • Maybe I don't understand roaming properly, so perhaps this is obvious from that brief description, but what if one or more of those users is a roaming user? – Martin Doms Dec 06 '11 at 21:13
  • There is no default folder in the standard install of Windows where *all* users have write access. You'll have to create one yourself. – Hans Passant Dec 06 '11 at 22:05
  • The write access isn't an issue, I'm granting write access in my installer. Thanks though :) – Martin Doms Dec 06 '11 at 22:13
  • Already an old post, but I use this solution with success http://stackoverflow.com/questions/14752048/config-file-location-for-any-user-workstation-specific-config#14752549 – Rolfi Sep 20 '13 at 11:43

2 Answers2

4

Here is a good explanation of the appdata folder and other items related to roaming user.

According to the MSDN Documentation:

CommonApplicationData is "the directory that serves as a common repository for application-specific data that is used by all users"

whereas

LocalApplicationData is "the directory that serves as a common repository for application-specific data that is used by the current, non-roaming user".

competent_tech
  • 44,465
  • 11
  • 90
  • 113
0

My preference for this is Application Settings which can be application wide or per user as you wish per setting.

kenny
  • 21,522
  • 8
  • 49
  • 87
  • Application scoped settings cannot be altered at runtime, so they're only suitable for values that never change. It might work for op, but probably not based on his specific question. – Tony Cheetham Apr 05 '18 at 10:24