首页 > 代码库 > C#Appconfig的读取与修改

C#Appconfig的读取与修改

一、C#读取Appconfig内容

private void button1_Click(object sender, EventArgs e)
{
string fileName=System.IO.Path.GetFileName(Application.ExecutablePath);
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(fileName);
string value = http://www.mamicode.com/config.AppSettings.Settings["ip"].Value = http://www.mamicode.com/txtIP.Text;
string value1 = config.AppSettings.Settings["username"].Value = http://www.mamicode.com/txtUserName.Text;
string value2 = config.AppSettings.Settings["userpwd"].Value = http://www.mamicode.com/txtPassword.Text;
config.Save();
MessageBox.Show("保存成功!");

}

二、修改Appconfig

private void ServerSetting_Load(object sender, EventArgs e)
{
string fileName = System.IO.Path.GetFileName(Application.ExecutablePath);
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(fileName);
string ip = config.AppSettings.Settings["ip"].Value;
string username = config.AppSettings.Settings["username"].Value ;
string userpwd = config.AppSettings.Settings["userpwd"].Value ;
txtIP.Text = ip;
txtUserName.Text = username;
txtPassword.Text = userpwd;
}

C#Appconfig的读取与修改