C # how to operate the config file

Source: Internet
Author: User

The following is the definition of app. config or web. config. A parameter is defined. The key is Isinit and the value is false.
<? Xml version = "1.0"?>
<Configuration>
<Deleetask>
<Add key = "IsInit" value = "false"/>
</AppSettings>
</Configuration>

The method definition for reading and writing the config file is as follows:

Write:

Copy codeThe Code is as follows: internal void settingApp_write (string key, string val)
{
System. Configuration. Configuration config = ConfigurationManager. OpenExeConfiguration (ConfigurationUserLevel. None );
Config. etettings. Settings ["IsInit"]. Value = val;
Config. Save (ConfigurationSaveMode. Modified );
ConfigurationManager. RefreshSection ("receivettings ");
}

Read:Copy codeThe Code is as follows: internal string settingApp_read (string key)
{
Var val = ConfigurationManager. deleetask[ key];
Return val;
}

Usage:

Write test:

SettingApp_write ("IsInit", "true ");

Fetch test:

Var setting = settingApp_read ("Isinit ");

This level of modification is the configuration file modification at the project level, that is, the operation of the config file under the Bin directory of your final program.

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.