代码:
string str = txtMusic.Text;
//写配置
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["backMusic"].Value = str;
//config.Save(ConfigurationSaveMode.Modified);
//ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
config.Save(ConfigurationSaveMode.Modified);配置文件:<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<appSettings>
<add key="backMusic" value=""/>
</appSettings>
</configuration>
string str = txtMusic.Text;
//写配置
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["backMusic"].Value = str;
//config.Save(ConfigurationSaveMode.Modified);
//ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
config.Save(ConfigurationSaveMode.Modified);配置文件:<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<appSettings>
<add key="backMusic" value=""/>
</appSettings>
</configuration>
解决方案 »
- sql问题
- 文件操作问题:Normal file does not contain a definition of 'File Delete Operator
- 如何求两个时间点包括几个季度??
- 在dataGridView中判断某列是否有某值,若没有某值报错
- 最后40分求一打印控件!!
- 困惑问题:mdi窗体,父窗体控件如何调用子窗体内的控件的事件处理程序
- 如何在2005中不用写代码就能把textbox与datasource绑定?
- 关于单元测试(NUnit.org)
- 我写了个网络电视。怎么给你们?
- 求助(关于图形编辑的,很急)
- c#vs里面如何复制图片
- winform 里如何获取fastreport控件的值 或者是将 winform 窗体山的值传给fastreport
http://kb.cnblogs.com/a/1274467/
传送门还不行+我Q453367672
public void Modify(string key, string strValue) //两个参数:要修改的键值 和 要修改的新值;
{
string flagstr = strValue;
if (strValue == string.Empty)
{
MessageBox.Show("连接串不能为空!");
return;
}
//string XPath = "/configuration/userInfo/add[@key='?']";
try
{
string XPath = "/configuration/appSettings/add[@key='?']";
XmlDocument domWebConfig = new XmlDocument(); //domWebConfig.Load((HttpContext.Current.Server.MapPath("web.config")));
domWebConfig.Load(filepath);
XmlNode addKey = domWebConfig.SelectSingleNode((XPath.Replace("?", key))); if (addKey == null)
{
//Response.Write("<script>alert (\"没有找到<add key='" + key + "' value=.../>的配置节\")</script>");
MessageBox.Show("没有找到<add key='" + key + "'>的配置节");
return;
}
addKey.Attributes["value"].InnerText = strValue;
domWebConfig.Save(filepath);
MessageBox.Show("数据库连接配置成功","信息提示");
}
catch
{
return;
} }