The specific method of C # operation config file

Source: Internet
Author: User
Tags definition config

The following is the definition of app.config or web.config, which 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>

The following is the method definition for the read and write config file:

Write:

Copy Code code as follows:


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:

Copy Code code as follows:


Internal string Settingapp_read (string key)


{


var val = Configurationmanager.appsettings[key];


return Val;


}

How to use:

Write test:

Settingapp_write ("Isinit", "true");

To remove a 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.

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.