本帖最后由 dillon00072002 于 2014-09-26 11:09:19 编辑

解决方案 »

  1.   

    获得XXX么?
    我有一个xml是这样的
    <configuration>
      <appSettings>
        <add key="ServerIP" value="192.168.1.120" />
        <add key="ListenPort" value="5555" />
        <add key="MaxSize" value="1024" />
        <add key="MaxCon" value="20" />
      </appSettings>
    </configuration>
    我获取某个节点的value是使用了 XmlDocument doc = new XmlDocument();
    doc.Load(Environment.CurrentDirectory + "/app.config");
     XmlNodeList nodes = doc.GetElementsByTagName("add");
    var ServerIP = nodes.Cast<XmlNode>().Where(d => d.Attributes["key"].Value == "ServerIP").First().Attributes["value"].Value;
      

  2.   

    你的应该大同小异 改下就可以用了 不过不是value应该是节点的text或者什么的吧
      

  3.   

    是获取最后一行property里边的数据库连接信息
      

  4.   


    你这个是配置文件?直接可以这样获取啊
    ConfigurationManager.AppSettings["MaxCon"]
      

  5.   


    我当然知道 不过我看到xxx.exe.config 我就闹心... 我代码上有洁癖 看不得这样的东西..还不能把exe去掉..所以我只能自己添加一个假"配置文件" 自己完成读写操作了.
      

  6.   


    我当然知道 不过我看到xxx.exe.config 我就闹心... 我代码上有洁癖 看不得这样的东西..还不能把exe去掉..所以我只能自己添加一个假"配置文件" 自己完成读写操作了.
    刚才用的办法解决了,现在又出了一个问题,我怎么样才能修改这个字段里边的东西。。
      

  7.   


    public static void SaveConfig(string ConnenctionString, string strKey)
            {
                XmlDocument doc = new XmlDocument();
                //获得配置文件的全路径
                string strFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                doc.Load(strFileName);
                //找出名称为“add”的所有元素
                XmlNodeList nodes = doc.GetElementsByTagName("add");
                for (int i = 0; i < nodes.Count; i++)
                {
                    //获得将当前元素的key属性
                    XmlAttribute att = nodes[i].Attributes["key"];
                    //根据元素的第一个属性来判断当前的元素是不是目标元素
                    if (att.Value == strKey)
                    {
                        //对目标元素中的第二个属性赋值
                        att = nodes[i].Attributes["value"];
                        att.Value = ConnenctionString;
                        break;
                    }
                }
                //保存上面的修改
                doc.Save(strFileName);
            }
      

  8.   

    当然了 这也是根据我的config来配置的  具体里面的节点 你可以自行修改