首页 > 移动平台 > 详细

C#Appconfig的读取与修改

时间:2017-04-11 13:18:38      阅读:338      评论:0      收藏:0      [点我收藏+]

一、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 = config.AppSettings.Settings["ip"].Value = txtIP.Text;
string value1 = config.AppSettings.Settings["username"].Value = txtUserName.Text;
string value2 = config.AppSettings.Settings["userpwd"].Value = 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的读取与修改

原文:http://www.cnblogs.com/lpfblog/p/6692911.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!