C#Appconfig的读取与修改
Posted 软件开发总结
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 = 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的读取与修改的主要内容,如果未能解决你的问题,请参考以下文章
c# app.config是否只用在程序运行的开始阶段,在程序运行过程中能不能进行保存和更新?
winform中怎么在app.config中配置一个节点读取本地文件夹的路径