// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Configuration; namespace E { public class Program { public static string GetSetting(string name) { return ConfigurationManager.AppSettings[name]; } public static void SetSetting(string name, string val) { Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); cfg.AppSettings.Settings[name].Value = val; cfg.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); } public static void Main(string[] args) { Console.WriteLine(GetSetting("foobar")); SetSetting("foobar", "123"); Console.WriteLine(GetSetting("foobar")); } } }