WinForm How to change the content in the app. config file

Source: Internet
Author: User

The following methods are modified, and the add-in app. config does not show the modified stuff.

Method One: Through the use of System.Xml.XmlDocument to the image of the method in Bin\debug\~.vshost.exe.config configuration changes. (This method will not take effect until the next time the program is active until you clear the item and re-modify it to restore the configuration information you wrote)

Public Static voidSetValue (StringAppKey,StringAppvalue)
{
System.Xml.XmlDocument XDoc= NewSystem.Xml.XmlDocument ();
Xdoc.load (System.Windows.Forms.Application.ExecutablePath+ ". config");

System.Xml.XmlNode XNode;
System.Xml.XmlElement xElem1;
System.Xml.XmlElement xElem2;
XNode=Xdoc.selectsinglenode ("AppSettings");

XElem1=(System.Xml.XmlElement) Xnode.selectsinglenode ("add[@key = '" + AppKey + " '] );
            if (xElem1 != null) Xelem1.setattribute ( "value             else
            {

If this does not add
XElem2=Xdoc.createelement ("Add");
Xelem2.setattribute ("Key", AppKey);
Xelem2.setattribute ("value", Appvalue);
Xnode.appendchild (XELEM2);
}
Xdoc.save (System.Windows.Forms.Application.ExecutablePath + ". config");
}

< Span style= "color: #000000;" >< Span style= "color: #800000;" >< Span style= "color: #800000;" > method Two: Use the configuration to modify the image. (This method takes effect immediately, but does not take effect the next time you activate)

< Span style= "color: #800000;" >< Span style= "color: #000000;" >   CONF. appsettings.settings["FilePath"]. Value = FBD. SelectedPath (new value for setup);   
  conf. Save (configurationsavemode.modified);
 configurationmanager.refreshsection ("appSettings");

WinForm How to change the content in the app. config file

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.