AppKey is keyAppValue is Valuepublic static void SetValue (string AppKey, string AppValue) {//System.Configuration.ConfigurationSettings.AppSettings.Set(AppKey,AppValue); XmlDocument xDoc = new XmlDocument (); xDoc.Load (System.Windows.Forms .Application.executablepath ".config"); XMLNode XNode; XMLELEMENT Xelem2;
XNode = xdoc.selectsinglenode ("// appsettings"); Xelem1 = (XMLELEMENT) XNode.selectsinglenode ("// add [@ Key = '" appkey ""); if (Xelem1! = null) Xelem1. SetAttribute ( "value", AppValue); else {xElem2 = xDoc.CreateElement ( "add"); xElem2.SetAttribute ( "key", AppKey); xElem2.SetAttribute ( "value", AppValue); xNode.AppendChild (xElem2) } XDoc.save (System.Windows.Forms.Application.executablePath ".config");}