欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

使用ConfigurationManager類 讀寫配置文件

系統(tǒng) 1897 0
?
分類:? .Net freamework ? 1165人閱讀 ? 評(píng)論 (0) ? 收藏 ? 舉報(bào)

使用ConfigurationManager類 讀寫配置文件app.config,以下為代碼:

?

  1. using ?System;??
  2. using ?System.Configuration;??
  3. ??
  4. static ? class ?Program??
  5. ????{??
  6. ???????? static ? void ?Main()??
  7. ????????{??
  8. ????????????showConfig();??
  9. ????????????UpdateAppSettings();??
  10. ????????????showConfig();??
  11. ??
  12. ????????????Console.ReadKey( true );??
  13. ????????}??
  14. ??
  15. ???????? private ? static ? void ?showConfig()??
  16. ????????{??
  17. ???????????? string ??=?ConfigurationManager.AppSettings[ "Directory" ];??
  18. ????????????Console.WriteLine( "AppSetting配置節(jié)?Path?key的value為:" ?+?dir?+? "/n" );??
  19. ????????}??
  20. ??
  21. ???????? ///?<summary> ??
  22. ???????? ///?UpdateAppSettings? ??
  23. ???????? ///?</summary> ??
  24. ???????? public ? static ? void ?UpdateAppSettings()??
  25. ????????{??
  26. ???????????? //?Get?the?configuration?file.? ??
  27. ????????????Configuration?config?=?ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);??
  28. ????????????Console.WriteLine( "config.FIlePath:?" ?+?config.FilePath?+? "/n" );??
  29. ????????????config.AppSettings.Settings[ "Directory" ].Value?=? "tset" ;??
  30. ??
  31. ???????????? //?Save?the?configuration?file.? ??
  32. ????????????config.AppSettings.SectionInformation.ForceSave?=? true ;??
  33. ????????????config.Save(ConfigurationSaveMode.Modified);??
  34. ???????????? //?Force?a?reload?of?the?changed?section.? ??
  35. ????????????ConfigurationManager.RefreshSection( "appSettings" );??
  36. ????????}???

app.config內(nèi)容:

?

?

  1. <? xml ? version = "1.0" ? encoding = "utf-8" ? ?> ??
  2. < configuration > ??
  3. ?? < appSettings > ??
  4. ???? < add ? key = "Directory" ? value = "C:/Documents?and?Settings" /> ??
  5. ?? </ appSettings > ??
  6. </ configuration > ??

?

?

代碼結(jié)果:app.config只能作為初始化的定義,工程生成后運(yùn)行程序集名稱.exe 修改生成后的 程序集名稱.exe.Config文件

一開始調(diào)試時(shí)看到控制結(jié)果是想要的結(jié)果,但看app.config配置文件內(nèi)容沒變(vs2008 F5調(diào)試模式下是修改 程序集名稱.vshost.exe.config配置文件)還以為是代碼有問題,網(wǎng)上搜,也有人碰過到此現(xiàn)像,原來是自己沒有理解到MSDN的說明。(還是有文化差異?。?

如:??????Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
??????????? Console.WriteLine("config.FIlePath: " + config.FilePath + "/n");

查看config.filePath值,即了解明白了。

?

4.0的類庫:? http://msdn.microsoft.com/en-us/library/ms134265(v=VS.100).aspx

?

注意:此類是.net2.0后新增。

必須要先在工程里添加system.configuration.dll程序集的引用。
(在解決方案管理器中右鍵點(diǎn)擊工程名稱,在右鍵菜單中選擇添加引用,.net->組件名稱->下即可找到)
添加引用后可以使用System.Configuration空間下的ConfigurationManager類.

?

引用資源:
http://www.ajaxline.com/node/258
http://www.codeproject.com/KB/cs/SystemConfiguration.aspx
http://www.cnblogs.com/interboy/archive/2007/04/22/722894.html ?????????? 使用ConfigurationManager類讀寫web.config

使用ConfigurationManager類 讀寫配置文件


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會(huì)非常 感謝您的哦?。?!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 91亚洲国产成人精品性色 | 亚洲字幕在线观看 | 玖玖国产 | 久久95| 色偷偷成人网免费视频男人的天堂 | 成年人在线看片 | 狠狠色狠狠色 | 国产精品国产精品国产专区不卡 | 一区二区日韩 | 人妻熟女久久久久久久 | 久久激情av | 国产精品一区二区三区免费 | 亚洲影视久久 | 秋霞久久国产精品电影院 | 被摁着灌浓精囚禁高h1v1 | 亚洲免费一区 | 学院传说之三生三世桃花缘 | 欧美激情欧美激情在线五月 | 欧美一级α | 欧美久久亚洲精品 | 在线视频二区 | 久久精品探花 | 久久久99精品免费观看精品 | 免费观看视频91 | 亚洲人一区 | 亚洲精品一区久久狠狠欧美 | 一区二区三区视频在线 | 国产精品欧美亚洲日本综合 | 欧美操操操 | 免费精品美女久久久久久久久久 | 人妻体内射精一区二区三四 | 免费在线观看成人 | 成人不卡 | 免费国产一区 | 日本一区欧美 | 久久一区精品 | 亚州天堂网 | 日本无卡码免费一区二区三区 | 国产一区二区av | 日本三级网址 | 日本网站在线播放 |