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)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 丰都县| 崇义县| 莱芜市| 杭州市| 抚远县| 兴仁县| 郯城县| 徐闻县| 介休市| 连城县| 五河县| 项城市| 永州市| 华坪县| 林芝县| 龙胜| 太湖县| 黑龙江省| 饶平县| 平江县| 永安市| 遂平县| 页游| 乌鲁木齐市| 伊通| 张掖市| 桂平市| 呼伦贝尔市| 桦南县| 枣阳市| 阿克陶县| 郁南县| 安康市| 仁寿县| 财经| 青浦区| 鱼台县| 司法| 元氏县| 诏安县| 泉州市|