January 17th, 2012, 03:59 AM
How add/update user specific configuration settings in WPF
I want to manage user specific configuration settings in WPF application configuration file (app.config). While setup (.msi using custom action) I ask user to enter some of the configuration parameters and want to store it in app.config. Also allows user to update these settings through configuration window. I tried following two approaches but didn't working as per expectation.
Approach 1: I added configurable parameters to appSettings section of app.config file. While setup I accepts values for those parameters and write it to app.config using ConfigurationManager. It's working fine. Here configuration are common to all the users.
Issue: Due to Windows 7 OS security unable to write/update configuration parameters value when user run application and modify the same from the configuration window. Since the app.config file stored under "Program Files" Win 7 security not allowing it to modify. It is working fine if I use "run as administrator" option.
Approach 2: Stored configurable settings to Properties.Settings.Default (WPF Project -> Properties -> Settings) which added to app.config file under userSettings/WPFSamples.Properties.Settings section. It has resolved issue with Windows 7 security now user can change the values of configurable parameters from configuration window and it updated to user setting file (C:/Users/DevUser1/AppData/Local) using Properties.Settings.Default. This approach allows to store user specific configuration.
Issue: While setup I accepts configurable values but not able to write it to user configuration file using Properties.Settings.Default (Properties.Settings.Default.Save()). It didn't throwing any exception but it has not been written anywhere since the user settings file (C:/Users/DevUser1/AppData/Local) isn't created until user start the application, modify the configurable parameters and saves it.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.