C #-Use ConfigurationManager to save data to app. Config

Source: Internet
Author: User

1. ConfigurationManager namespace: Using System.Configuration;

2. To is able to save you has to use a configuration object returned by the Openexeconfiguration Method

//Create The ObjectConfiguration config =configurationmanager.openexeconfiguration (configurationuserlevel.none);//Make changesConfig. appsettings.settings["Username"]. Value =Txtusername.text;config. appsettings.settings["Password"]. Value =txtPassword.Text;//save to apply ChangesCONFIG. Save (configurationsavemode.modified); Configurationmanager.refreshsection ("appSettings");

3. When you run the your application with F5,

    • Your code is compiled,
    • bin bin\Debug The executable is copied to the or subdirectory of your source code directory,
    • Your app.config yourexecutable.exe.config is copied as to that directory, and
    • Your executable is started in that directory.

Thus, your application uses the  yourexecutable.exe.config  in the  bin  or  bin\debug  directory, and it is  there  that  ConfigurationManager  saves The changes, not in your source code directory. This won ' t is a issue after deploying your application, because then, changes'll go to  yourexecutable.exe.co Nfig  in The deployment directory, which is what you want.

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.