using System.Configuration; ... Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigNode rootNode = config.AppSettings.Settings; rootNode.AddValue("ConnectionString", "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=UserPassword;"); config.Save(ConfigurationSaveMode.Modified);
using System.Configuration; ... Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigNode rootNode = config.AppSettings.Settings; rootNode.AddValue("CustomSetting", "Custom Value"); config.Save(ConfigurationSaveMode.Modified);In this example, we are adding a new custom setting key called "CustomSetting" along with its value to the AppSettings section of the application's configuration file. We follow the same steps as in the previous example. We can determine that the package library is System.Configuration as it is responsible for managing configuration files in C#.