Configuration. ConfigurationManager is a new class of. Net2.0. In winform, you must add a reference to System. Configuration. dll to call it.
Configuration data cannot be read in real time during winform configuration files. Because of the habits of web programs, after the configuration file is changed in the web program, the application will automatically restart once, so the configuration will automatically take effect. However, the winform program does not have this mechanism, so Configuration. ConfigurationManager does not automatically update the called Configuration.
Manual implementation: discard Configuration. ConfigurationManager and directly read xml documents. 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 ();
}