WINDOW program, app.config operation

xiaoxiao2021-03-06  43

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");}

转载请注明原文地址:https://www.9cbs.com/read-79190.html

New Post(0)