<? xml version = " 1.0 " encoding = " utf-8 " ?> < configuration > < appSettings > < add key = " PicPath " value = " D:StudySampleCSharpAddTextToPic " > iuu </ add > <!-- asdfasdfasdf --> < add key = " ImageText " value = " Xiao A by johnny " /> </ appSettings > </ configuration > private void Button1_Click( object sender, System.EventArgs e) ... { string strFileName = @"D:StudySampleCSharpAddTextToPicInitialize.xml"; if (System.IO.File.Exists(strFileName) == true) ...{ System.Xml.XmlDocument XmlDoc = new System.Xml.XmlDocument(); XmlDoc.Load(strFileName); System.Xml.XmlElement XmlEle = XmlDoc["configuration"]; if (XmlEle != null) ...{ XmlEle = XmlEle["appSettings"]; } if (XmlEle != null) ...{ foreach (System.Xml.XmlNode XmlNode in XmlEle) ...{ if (XmlNode.Name == "add") ...{ switch(XmlNode.Attributes.GetNamedItem("key").Value) ...{ case "PicPath": TextBox1.Text = XmlNode.Attributes.GetNamedItem("value").Value + " "; break; case "ImageText": TextBox1.Text = TextBox1.Text + XmlNode.Attributes.GetNamedItem("value").Value; break; default: break; } } } } } }