C# winform 修改app.config配置文件的实现类
[code=C#]
class Configuration
{
public static string fileName=System.IO.Path.GetFileName(Application.ExecutablePath);
public static bool addSetting(string key,string value){
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(fileName);
config.AppSettings.Settings.Add(key, value);
config.Save();
return true;
}
public static string getSetting(string key){
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(fileName);
string value=config.AppSettings.Settings[key].Value;
return value;
}
public static bool updateSeeting(string key, string newValue)
{
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(fileName);
string value = config.AppSettings.Settings[key].Value=newValue;
config.Save();
return true;
}
}
}
[/code]
本文来自CSDN博客,出处:http://blog.csdn.net/fsict/archive/2009/02/02/3858965.aspx