打开一个应用程序,然后配置数值,譬如说对于config中<CalendarWoke OnlineTime="2" MobileTime="2" EmailTime="2"/>,我想修改OnlineTime=5,该如何编写程序?

解决方案 »

  1.   

    你可以把这个config文件当作xml文件来读写
      

  2.   

    哦,谢谢了.那如何往xml文件中写入数据啊?
      

  3.   


    百度一下,XML的读写,就可以了。
    很方便的,我正在研究
      

  4.   

    http://kb.cnblogs.com/page/42226/?page=1这个例子很普遍,也大致能学会了
      

  5.   

    操作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);
            } 
    参考