Using System.Xml;
----------------------------------------------read out the node values in the XML file
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load (Application.startuppath + "\" + "STOExpress.ContentPush.WindowsService.Client.exe.config");
Get top-level node list
if (xmldoc.documentelement! = null) {
XmlNodeList topm = xmlDoc.DocumentElement.ChildNodes;
foreach (XmlElement el in from XmlElement element in topm where element. Name.tolower () = = "appsettings" SELECT element. ChildNodes into NodeList where nodelist. Count > 0 from XmlElement el in NodeList where el! = NULL select EL) {
if (el. attributes["Key"]. Value = = "SecurityKey") {
Txtsecuritykey.text = el. attributes["Value"]. Value;
}
if (el. attributes["Key"]. Value = = "Clientno") {
Txtclientcode.text = el. attributes["Value"]. Value;
}
if (el. attributes["Key"]. Value = = "ClientType") {
Txtclienttype.text = el. attributes["Value"]. Value;
}
}
}
---------------------------------------------write the value of the XML file
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load (Application.startuppath + "\" + "STOExpress.ContentPush.WindowsService.Client.exe.config");
Get top-level node list
if (xmldoc.documentelement! = null) {
XmlNodeList topm = xmlDoc.DocumentElement.ChildNodes;
foreach (XmlElement el in from XmlElement element in topm where element. Name.tolower () = = "appsettings" SELECT element. ChildNodes into NodeList where nodelist. Count > 0 from XmlElement el in NodeList where el! = NULL select EL) {
if (el. attributes["Key"]. Value = = "SecurityKey") {
El. attributes["Value"]. Value = TxtSecurityKey.Text.Trim ();
}
if (el. attributes["Key"]. Value = = "Clientno") {
El. attributes["Value"]. Value = TxtClientCode.Text.Trim ();
}
if (el. attributes["Key"]. Value = = "ClientType") {
El. attributes["Value"]. Value = TxtClientType.Text.Trim ();
}
}
}
Xmldoc.save (Configfilename);
Read and write XML configuration files