如何改变config的数据? 打开一个应用程序,然后配置数值,譬如说对于config中<CalendarWoke OnlineTime="2" MobileTime="2" EmailTime="2"/>,我想修改OnlineTime=5,该如何编写程序? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以把这个config文件当作xml文件来读写 哦,谢谢了.那如何往xml文件中写入数据啊? 百度一下,XML的读写,就可以了。很方便的,我正在研究 http://kb.cnblogs.com/page/42226/?page=1这个例子很普遍,也大致能学会了 操作XMLpublic void UpdateConfigValueOfKey(string Key , string KeyValue) { XmlDocument doc=new XmlDocument(); string strFileName=AppDomain.CurrentDomain.BaseDirectory.ToString()+"App.config"; doc.Load(strFileName); XmlNodeList nodes=doc.GetElementsByTagName("add"); for(int i=0;i<nodes.Count;i++) { XmlAttribute att=nodes[i].Attributes["key"]; if (att.Value.ToString().Equals(Key)) { att=nodes[i].Attributes["value"]; att.Value=KeyValue; break; } } doc.Save(strFileName); } 参考 请教:C#的共用体运行出错的疑问? c#从字符串中取出所有的指定字符串存入数组变量 求一个C#实现 C#.net , 如何让byte[]数组大小随Socket的Receive接收的信息内容大小来变化 这个格式的xml文件的url怎么下载(https://www.test.com/downfile?w=AFKSDFSLGFD-SDFE) 窗体中添加控件,哪个方法好? 求c# 可用的mapobject2.4安装程序!! C#的内部类不能直接访问外部类的非静态成员? C#中DataFrid不能实现分页功能 怎样创建资源文件? 请教一个动画绘制的问题 今天的分数用完了,希望关注
百度一下,XML的读写,就可以了。
很方便的,我正在研究
public void UpdateConfigValueOfKey(string Key , string KeyValue)
{
XmlDocument doc=new XmlDocument();
string strFileName=AppDomain.CurrentDomain.BaseDirectory.ToString()+"App.config";
doc.Load(strFileName);
XmlNodeList nodes=doc.GetElementsByTagName("add");
for(int i=0;i<nodes.Count;i++)
{
XmlAttribute att=nodes[i].Attributes["key"];
if (att.Value.ToString().Equals(Key))
{
att=nodes[i].Attributes["value"];
att.Value=KeyValue;
break;
}
}
doc.Save(strFileName);
}
参考