public static void Createappsettings () {//Get the application configuration file. System.Configuration.Configuration config = configurationmanager.openexeconfiguration (configurationuserlevel. None); String sectionname = "AppSettings"; Add an entry to appSettings. int appstgcnt = ConfigurationManager.AppSettings.Count; String NewKey = "NewKey" + appstgcnt.tostring (); String newvalue = DateTime.Now.ToLongDateString () + "" + DateTime.Now.ToLongTimeString (); Config. APPSETTINGS.SETTINGS.ADD (NewKey, newvalue); Save the configuration file. Config. Save (configurationsavemode.modified); Force a reload of the changed section. This//makes the new values available for reading. Configurationmanager.refreshsection (sectionname); Get the AppSettings section. Appsettingssection appsettingsection = (appsettingssection) config. GetSection (sectionname); Console.WriteLine (); Console.WriteLine ("Using GetSection (String)."); Console.WriteLine ("AppSettingS section: "); Console.WriteLine (AppSettingSection.SectionInformation.GetRawXml ());}
Configurationmanager.getsection usage