How to update appSettings in a WPF app?

Have you looked into the ConfigurationManager class? It provides a more robust interface to the app.config file and you can do something like this:

Configuration oConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
oConfig.AppSettings.Settings["PreferenceToRemember"].Value = "NewValue";
oConfig.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection("appSettings");

Just remember to import System.Configuration into your project. It isn't added by default.


Take a look at the Configuration class and Enterprise Library. You can find detailed instructions here.