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

           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++)

           {
           //獲得將當前元素的key屬性
           XmlAttribute att=nodes[i].Attributes["key"];
           //根據元素的第一個屬性來判斷當前的元素是不是目標元素
           if (att.Value== ""+configKey+"")
           {
           //對目標元素中的第二個屬性賦值
           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++)
               {
                   //獲得將當前元素的key屬性
                   XmlAttribute att = nodes[i].Attributes["key"];
                   //根據元素的第一個屬性來判斷當前的元素是不是目標元素
                   if (att.Value == "" + configKey + "")
                   {
                       //對目標元素中的第二個屬性賦值
                       att = nodes[i].Attributes["value"];
                       tempStr= att.Value;
                   }
               }
               //保存上面的修改
               return tempStr;
           }

           }

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

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


          網站導航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 三亚市| 太仆寺旗| 武乡县| 左贡县| 台湾省| 黔南| 耿马| 芦山县| 宣武区| 贵州省| 长春市| 北碚区| 万全县| 介休市| 宜昌市| 柘城县| 南投县| 宁陵县| 秭归县| 东莞市| 祥云县| 南川市| 象州县| 防城港市| 田阳县| 临朐县| 保康县| 邳州市| 葵青区| 思茅市| 青田县| 乐清市| 泽普县| 江陵县| 托克逊县| 咸丰县| 麻阳| 额尔古纳市| 洪洞县| 谷城县| 巴南区|