C # How to manipulate the config file

Source: Internet
Author: User
The following is the definition of app. Config or Web. config, defines a parameter, the key is Isinit, and the value is False
<?xml version= "1.0"?>
<configuration>
<appSettings>
<add key = "Isinit" value= "false"/>
</appSettings>
</configuration>

Here is the method definition for reading and writing the config file:

Write:

internal void Settingapp_write (string key, String val)  {      System.Configuration.Configuration config = Configurationmanager.openexeconfiguration (configurationuserlevel.none);  Config. appsettings.settings["Isinit"]. Value = val;  Config. Save (configurationsavemode.modified);  Configurationmanager.refreshsection ("appSettings");  }

Read:

Internal string Settingapp_read (string key) {     var val = configurationmanager.appsettings[key];     return Val; }

How to use:

Write test:

Settingapp_write ("Isinit", "true");

Remove test:

var setting = Settingapp_read ("Isinit");

This level of modification is the project-level config file modification, which is the operation of the config file in your final program Bin directory.


Related Article

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.