Config operation class

Source: Internet
Author: User
Using system;
Using system. xml;
Using system. configuration;
/** // <Summary>
/// Read the configuration file
/// Config operation class
/// </Summary>
Public class confighelper
{
Public confighelper ()
{
//
// Todo: add the constructor logic here
//
}

Getconfigvalueofkey (string key) to get the value of the configuration file # region getconfigvalueofkey (string key) to get the value of the configuration file

Public String getconfigvalueofkey (string key)
{
Try
{
String value = configurationsettings. deleetask[ key];
// Console. writeline (key );
// Console. writeline (value );
Return value;
}
Catch (exception ex)
{
Console. writeline (ex. Message );
Console. writeline (ex. stacktrace );
Return "";
}
}
# Endregion

// # Region abstract createconfigvalueofkey needs to be developed
// Public void createconfigvalueofkey (string key, string keyValue)
//{
//
//}
// # Endregion

Updateconfigvalueofkey # region updateconfigvalueofkey
Public void updateconfigvalueofkey (string key, string keyValue)
{
Xmldocument Doc = new xmldocument ();
// Obtain the full path of the configuration file
String strfilename = appdomain. currentdomain. basedirectory. tostring () + "app. config ";
Console. writeline (strfilename );
// Return;
Doc. Load (strfilename );
// Find all elements named "add"

// Bool isexist = false;

Xmlnodelist nodes = Doc. getelementsbytagname ("add ");
For (INT I = 0; I <nodes. Count; I ++)
{
// Obtain the key attribute of the current element
Xmlattribute ATT = nodes [I]. attributes ["key"];
// Determine whether the current element is a target element based on the first attribute of the element.
If (Att. value. tostring (). Equals (key ))
{
// Assign values to the second attribute of the target Element
ATT = nodes [I]. attributes ["value"];
Att. value = keyValue;
// Isexist = true;
Break;
}
}
// Save the modification above
Doc. Save (strfilename );
}
# Endregion
}

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.