附件下载:http://files.cnblogs.com/files/qtiger/ShortcutAchieve.zip
代码实现最重要(增加引用using System.Configuration名称空间)
private void AccessAppSettings() { //获取Configuration对象 Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //根据Key读取<add>元素的Value string name = config.AppSettings.Settings["name"].Value; //写入<add>元素的Value config.AppSettings.Settings["name"].Value = "xieyc"; //增加<add>元素 config.AppSettings.Settings.Add("url", "http://www.xieyc.com"); //删除<add>元素 config.AppSettings.Settings.Remove("name"); //一定要记得保存,写不带参数的config.Save()也可以 config.Save(ConfigurationSaveMode.Modified); //刷新,否则程序读取的还是之前的值(可能已装入内存) System.Configuration.ConfigurationManager.RefreshSection("appSettings"); }