About Configuration. ConfigurationManager

Source: Internet
Author: User
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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.