国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

C# 手動(dòng)讀寫app config 的源碼

2019-11-17 02:58:59
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
C# 手動(dòng)讀寫app config 的源碼
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ù)元素的第一個(gè)屬性來(lái)判斷當(dāng)前的元素是不是目標(biāo)元素 if (att.Value== ""+configKey+"")  { //對(duì)目標(biāo)元素中的第二個(gè)屬性賦值 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ù)元素的第一個(gè)屬性來(lái)判斷當(dāng)前的元素是不是目標(biāo)元素         if (att.Value == "" + configKey + "")         {             //對(duì)目標(biāo)元素中的第二個(gè)屬性賦值             att = nodes[i].Attributes["value"];             tempStr= att.Value;         }     }     //保存上面的修改     return tempStr; } }


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 沂南县| 天水市| 斗六市| 清流县| 南靖县| 泰安市| 嫩江县| 永定县| 张家口市| 汝阳县| 镇平县| 布拖县| 环江| 宣威市| 江油市| 苗栗县| 台中县| 临邑县| 朝阳县| 三河市| 太仆寺旗| 灯塔市| 读书| 嵊泗县| 阜康市| 长岛县| 从江县| 方山县| 丰城市| 大冶市| 名山县| 阿拉善右旗| 天气| 江北区| 山阳县| 甘德县| 永泰县| 镇原县| 武川县| 日照市| 黄浦区|