public static string GetValue (string AppKey) { try { string AppKeyValue = System.Configuration.ConfigurationSettings.AppSettings.Get (AppKey); return AppKeyValue; } catch (Exception ex) { / ; XmlDocument xDoc = new XmlDocument (); xDoc.Load (System.Windows.Forms.Application.ExecutablePath ".config"); XmlNode xNode; XmlElement xElem1; XmlElement xElem2; XNode = xdoc.selectsinglenode ("// appsettings"); Xelem1 = (XMLELEMENT) xnode.selectsinglenode ("// add [@ key = '" appkey "); ); Xelem2.SetaTribute ("Value", AppValue; XNode.Appendchild (Xelem2);} xDoc.save (System.windows.Forms.Application.executablePath ".config"); } #