<?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="Setting1" value="Very" /> <add key="Setting2" value="Easy" /> </appSettings> </configuration>
using System; using System.Collections.Generic; using System.Text; using System.Configuration; namespace AppSettings { class Program { static void ShowConfig() { // For read access you do not need to call OpenExeConfiguraton foreach(string key in ConfigurationManager.AppSettings) { string value = ConfigurationManager.AppSettings[key]; Console.WriteLine("Key: {0}, Value: {1}", key, value); } } static void Main(string[] args) { ShowConfig(); // Open App.Config of executable System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None); // Add an Application Setting. config.AppSettings.Settings.Add("ModificationDate", DateTime.Now.ToLongTimeString() + " "); // Save the changes in App.config file. config.Save(ConfigurationSaveMode.Modified); // Force a reload of a changed section. ConfigurationManager.RefreshSection("appSettings"); ShowConfig(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)