首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么在winform 中修改app.config的值

2012-08-22 
如何在winform 中修改app.config的值?如何在winform 中修改app.config的值?[解决办法]可以用写文件的方式,

如何在winform 中修改app.config的值?
如何在winform 中修改app.config的值?

[解决办法]
可以用写文件的方式,如:
public static bool WriteXml(string strKey, string strValue, string strFileName)
{
//写配置
try
{
XmlDocument doc = new XmlDocument();
doc.Load(strFileName);
XmlNode xAS = doc.SelectSingleNode("/configuration/applicationSettings");
XmlNode xNode = xAS.SelectSingleNode(String.Format("//setting[@name='{0}']", strKey));
foreach (XmlElement xEle in xNode)
{
if (xEle.Name == "value")
{
xEle.InnerText = strValue;
break;
}
}
doc.Save(strFileName);
doc = null;
return true;
}
catch
{
return false;
}
}
[解决办法]
作用域为“用户”的可以直接在程序里调用Properties.Settings.Default.Save()保存。

热点排行