C # Gets or sets the value of the specified config file

Source: Internet
Author: User

Execonfigurationfilemap This class provides the ability to modify and obtain the specified config;
Create a new instance of Execonfigurationfilemap ECF;
and set the Execonfigfilename property to the config file path to operate;
Using the Configurationmanager.openmappedexeconfiguration method to get the object Configuration Config
Invokes the config provided by the Configuration object instance. Appsettings.settings[key]. Value can be modified or obtained by appsetting;
If the modification requires a call to the Save method,config. Save ();

<summary>///Get the AppSetting node value in the custom Index.config file//</summary>///<param name= "key" > node name </ param>///<returns></returns>public static string Getindexconfigvalue (String key) {string    Indexconfigpath = @ "D:\indexConfig";    Execonfigurationfilemap ECF = new Execonfigurationfilemap (); Ecf.    Execonfigfilename = Indexconfigpath;    Configuration config = configurationmanager.openmappedexeconfiguration (ECF, Configurationuserlevel.none); return CONFIG. Appsettings.settings[key]. Value;} <summary>///Setting the AppSetting node value in the custom Index.config file//</summary>///<param name= "key" > node name </ param>///<returns></returns>public static bool Setindexconfigvalue (string key, String value) {string in       Dexconfigpath = @ "D:\indexConfig";    Execonfigurationfilemap ECF = new Execonfigurationfilemap (); Ecf.    Execonfigfilename = Indexconfigpath; Configuration config = configurationmanager.openmappedexeconfiguration (ECF, ConfiGurationuserlevel.none); Config. Appsettings.settings[key].    Value = value; Config.    Save (); return true;}

  

C # Gets or sets the value of the specified 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.