码迷,mamicode.com
首页 > 移动开发 > 详细

C#Appconfig的读取与修改

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

标签:manage   cat   text   event   ble   保存   str   ext   .sh   

一、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的读取与修改

标签:manage   cat   text   event   ble   保存   str   ext   .sh   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!