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