Update appSettings in App.Config for executable.

I wanted programmatically (for administrator) to update configuration settings for .Net 2.0 executable.
The new  in VS 2005 Properties.Settings class saves only user-scope settings, not application scope, which is inconvinient.

I've decided to use The easiest way to read/write AppSettings   from the very good article Read/Write App.config with .NET 2.0/Enterprise Library   However I noticed two issues:

 config.AppSettings.Settings (KeyValueConfigurationCollection class) has Add and Remove methods, but does not have Set method, so I had to create static helper function:
        public static void Set(KeyValueConfigurationCollection settings, string key, string value)
        {

            if (settings[key] != null)

            {

                settings.Remove(key);

            }

            settings.Add(key, value);

        }

 

Also if the appSettings element uses the File attribute,

config.Save() for executable updates the main file, not specified in File attribute "appSettings" section.So if the value is stored in the referenced file, saving "appSettings" to the main file has no effect.

 

posted @ Tuesday, November 21, 2006 3:48 PM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 4 and 3 and type the answer here:
 

Live Comment Preview:

 
«September»
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011