public class ConfigOperator
           {
           public string strFileName;
           public string configName;
           public string configValue;
           public ConfigOperator()
           {
           //
           // TODO: 在此處添加構(gòu)造函數(shù)邏輯
           //
           }

           public string ReadConfig1(string configKey)
           {
           configValue = "";
           configValue = ConfigurationSettings.AppSettings[""+configKey+""];
           return configValue;
           }
           
          //得到程序的config文件的名稱以及其所在的全路徑
           public void SetConfigName(string strConfigName)
           {
           configName = strConfigName;
           //獲得配置文件的全路徑
           GetFullPath();
           }

           public void GetFullPath()
           {
           //獲得配置文件的全路徑
           strFileName=AppDomain.CurrentDomain.BaseDirectory.ToString()+configName;
           }

           public void SaveConfig(string configKey,string configValue)
           {
           XmlDocument doc=new XmlDocument();
           doc.Load(strFileName);
           //找出名稱為“add”的所有元素
           XmlNodeList nodes=doc.GetElementsByTagName("add");
           for(int i=0;i<nodes.Count;i++)

           {
           //獲得將當(dāng)前元素的key屬性
           XmlAttribute att=nodes[i].Attributes["key"];
           //根據(jù)元素的第一個屬性來判斷當(dāng)前的元素是不是目標(biāo)元素
           if (att.Value== ""+configKey+"")
           {
           //對目標(biāo)元素中的第二個屬性賦值
           att=nodes[i].Attributes["value"];
           att.Value=configValue;
           break;
           }
           }
           //保存上面的修改
           doc.Save(strFileName);
           }

           public string ReadConfig(string configKey)
           {
               string tempStr = "";
               XmlDocument doc = new XmlDocument();
               doc.Load(strFileName);
               //找出名稱為“add”的所有元素
               XmlNodeList nodes = doc.GetElementsByTagName("add");
               for (int i = 0; i < nodes.Count; i++)
               {
                   //獲得將當(dāng)前元素的key屬性
                   XmlAttribute att = nodes[i].Attributes["key"];
                   //根據(jù)元素的第一個屬性來判斷當(dāng)前的元素是不是目標(biāo)元素
                   if (att.Value == "" + configKey + "")
                   {
                       //對目標(biāo)元素中的第二個屬性賦值
                       att = nodes[i].Attributes["value"];
                       tempStr= att.Value;
                   }
               }
               //保存上面的修改
               return tempStr;
           }

           }

          posted on 2010-04-26 15:36 sanmao 閱讀(380) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 吉安市| 格尔木市| 长顺县| 瓦房店市| 高尔夫| 钦州市| 宝坻区| 汕尾市| 通化县| 鹰潭市| 綦江县| 柏乡县| 沁水县| 舒城县| 海门市| 许昌市| 江山市| 阜宁县| 芮城县| 家居| 班戈县| 岳阳县| 安仁县| 临猗县| 福泉市| 广饶县| 苏尼特左旗| 苍溪县| 大石桥市| 中卫市| 德安县| 广河县| 通河县| 墨玉县| 永济市| 新余市| 贵州省| 芮城县| 辽中县| 颍上县| 沂源县|