Public class configoperator
{
Public String strfilename;
Public String configname;
Public String configvalue;
Public configoperator ()
{
//
// Todo: add the constructor logic here
//
}
Public String readconfig1 (string configkey)
{
Configvalue = "";
Configvalue = configurationsettings. deleettings ["" + configkey + ""];
Return configvalue;
}
// GetProgramThe name of the config file and its full path
Public void setconfigname (string strconfigname)
{
Configname = strconfigname;
// Obtain the full path of the configuration file
Getfullpath ();
}
Public void getfullpath ()
{
// Obtain 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 elements named "add"
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 = "" + configkey + "")
{
// Assign values to the second attribute of the target Element
ATT = nodes [I]. attributes ["value"];
Att. value = configvalue;
Break;
}
}
// Save the modification above
Doc. Save (strfilename );
}
Public String readconfig (string configkey)
{
String tempstr = "";
Xmldocument Doc = new xmldocument ();
Doc. Load (strfilename );
// Find all elements named "add"
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 = "" + configkey + "")
{
// Assign values to the second attribute of the target Element
ATT = nodes [I]. attributes ["value"];
Tempstr = Att. value;
}
}
// Save the modification above
Return tempstr;
}
}