views:

264

answers:

2

I'm using the Windows Forms Application settings architecture (or however you're supposed to refer to it) and am successfully saving user settings to AppData.

What I want to do is have some settings common to all users of a particular machine and some settings which roam with users across machines. For example I have some settings relating to a peripheral attached to the computer (model, settings etc.) and some user preferences like user interface colours.

The colours preferences should roam with the user, but the peripheral settings should stay on the local computer no matter who's logged on.

How can I mark these types of settings so that some get stored in All Users/AppData/... and some in [user name]/AppData/...?

Note that I don't want Application level settings - each computer the app will be installed on will have different settings.

I'm targetting .Net 3.0 if that makes a difference.

A: 

From the page you linked to:

Settings File Locations

The location of the app.exe.config and user.config files will differ based on how the application is installed. For a Windows Forms-based application copied onto the local computer, app.exe.config will reside in the same directory as the base directory of the application's main executable file, and user.config will reside in the location specified by the Application.LocalUserAppDataPath property. For an application installed by means of ClickOnce, both of these files will reside in the ClickOnce Data Directory underneath %InstallRoot%\Documents and Settings\username\Local Settings.

The storage location of these files is slightly different if a user has enabled roaming profiles, which enables a user to define different Windows and application settings when he or she is using other computers within a domain. In that case, both ClickOnce applications and non-ClickOnce applications will have their app.exe.config and user.config files stored under %InstallRoot%\Documents and Settings\username\Application Data.

For more information about how the Application Settings feature works with the new deployment technology, see ClickOnce and Application Settings. For more information about the ClickOnce Data Directory, see Accessing Local and Remote Data in ClickOnce Applications.

Mitch Wheat
That's fine but application settings aren't writeable at runtime - http://msdn.microsoft.com/en-us/library/aa730869%28VS.80%29.aspx - and user settings when roaming is enabled will roam with the user. Can I differentiate 'local' user settings (machine specific) from 'roaming' user settings (user specific)?
Mark Pim
+1  A: 

It is done through the [SettingsManageability] attribute. The LocalFileSettingsProvider class checks it, the presence of the attribute appears to be enough, as long as the app isn't ClickOnce deployed. Looks pretty useless, the settings designer has no support for it.

Hans Passant
Ah that's done it. Thanks :)
Mark Pim