码迷,mamicode.com
首页 > Windows程序 > 详细

winform中key读取修改

时间:2017-04-13 14:46:00      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:conf   settings   blog   使用   win   attribute   value   ret   element   

根据key name的名称读取value-----读取使用ConfigurationManager.AppSettings读取容易没读取到根目录中的key

public string GetXml(string name)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("app.config");
            XmlElement element = doc.SelectSingleNode("//add[@key=‘" + name + "‘]") as XmlElement;

            return  element.GetAttributeNode("value").Value;
        }

 

根据key name名称修改value值

       public void UpdateXml(string name, string value)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("app.config");
            XmlElement element = doc.SelectSingleNode("//add[@key=‘" + name + "‘]") as XmlElement;
            if (element != null)
            {
                XmlAttribute a = element.GetAttributeNode("value");
                if (a != null)
                {
                    a.Value = value;// 按实际需要来写
                    doc.Save("app.config");
                }
            }
        }

 

winform中key读取修改

标签:conf   settings   blog   使用   win   attribute   value   ret   element   

原文地址:http://www.cnblogs.com/bit-by-bit/p/6703364.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!