关于Configuration.ConfigurationManager

it2022-05-09  32

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();         }

转载于:https://www.cnblogs.com/tuyile006/archive/2008/06/22/1227667.html


最新回复(0)