关于Configuration.ConfigurationManager
生活随笔
收集整理的這篇文章主要介紹了
关于Configuration.ConfigurationManager
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Configuration.ConfigurationManager是.Net2.0的新類。在winform必須添加對System.Configuration.dll的引用才可以調用。
在做winform配置文件的時候總是不能實時讀取配置數據。因為web程序中的習慣,在web程序中配置文件更改后,應用程序會自動重啟一次,于是配置會自動生效。但winform程序沒有這個機制,于是Configuration.ConfigurationManager調用配置不會自動更新。
手工實現:拋棄Configuration.ConfigurationManager,直接讀xml文檔。
public?string?ReadAppSetting(string?key)
????????{
????????????string?xPath?=?"/configuration/appSettings//add[@key='"+key+"']";
????????????XmlDocument?doc?=?new?XmlDocument();
????????????string?exeFileName?=?System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
????????????doc.Load(exeFileName?+?".exe.config");
????????????XmlNode?node?=?doc.SelectSingleNode(xPath);
????????????return?node.Attributes["value"].Value.ToString();
????????}
在做winform配置文件的時候總是不能實時讀取配置數據。因為web程序中的習慣,在web程序中配置文件更改后,應用程序會自動重啟一次,于是配置會自動生效。但winform程序沒有這個機制,于是Configuration.ConfigurationManager調用配置不會自動更新。
手工實現:拋棄Configuration.ConfigurationManager,直接讀xml文檔。
public?string?ReadAppSetting(string?key)
????????{
????????????string?xPath?=?"/configuration/appSettings//add[@key='"+key+"']";
????????????XmlDocument?doc?=?new?XmlDocument();
????????????string?exeFileName?=?System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
????????????doc.Load(exeFileName?+?".exe.config");
????????????XmlNode?node?=?doc.SelectSingleNode(xPath);
????????????return?node.Attributes["value"].Value.ToString();
????????}
轉載于:https://www.cnblogs.com/tuyile006/archive/2008/06/22/1227667.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的关于Configuration.ConfigurationManager的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 嫁给普京的中国女人是谁
- 下一篇: 5分钟安全顾问 - 针对家庭办公室用户的