C # Manual read-write app config source code

Source: Internet
Author: User

public class Configoperator {public string strfilename, public string configname, public string configvalue, public confi Goperator () {////TODO: Add constructor logic here//} public string ReadConfig1 (string configkey) {ConfigValue = ""; ConfigValue = configurationsettings.appsettings["" +configkey+ ""]; return configvalue; }//Get the name of the program's config file and its full path public void Setconfigname (string strconfigname) {ConfigName = Strconfigname;//Get the full path of the configuration file GetFullPath (); } public void GetFullPath () {//Gets the full path of the configuration file strfilename=appdomain.currentdomain.basedirectory.tostring () +configname;} public void Saveconfig (string configkey,string configvalue) {XmlDocument doc=new XmlDocument (); Doc. Load (strFileName); Find all the elements named "Add" XmlNodeList nodes=doc. getElementsByTagName ("add"); for (int i=0;i<nodes. count;i++) {//Gets the key property of the current element XmlAttribute Att=nodes[i]. attributes["Key"]; Determines whether the current element is the target element if (ATT) based on the first attribute of the element. value== "" +configkey+ "") {//assigns a value att=nodes[i] to the second attribute in the target element. attributes["value"]; Att. Value=configvalue; Break}}//Save the above modification doc. Save (strFileName);     public string Readconfig (string configkey) {string tempstr = "";     XmlDocument doc = new XmlDocument (); Doc.     Load (strFileName); Find all the elements with the name "add" xmlnodelist nodes = Doc.     getElementsByTagName ("add"); for (int i = 0; i < nodes. Count; i++) {//Gets the key attribute of the current element XmlAttribute att = nodes[i].         attributes["Key"]; Determines whether the current element is the target element if (ATT) based on the first attribute of the element. Value = = "" + Configkey + "") {//assigns to the second attribute in the target element att = nodes[i].             attributes["value"]; Tempstr= Att.         Value; }}//Save the above modified return TEMPSTR; } }

  

C # Manual read-write app config source code

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.