App.config reads the modification summary in the WinForm project!

xiaoxiao2021-03-06  39

For the first time I wrote, you will bear with you, more encouragement! Thank you!

Just starting to do a NET program, to read and write the project profile app.conig, the following two methods are completed separately.

//read

public static string GetValue (string AppKey) {try {string AppKeyValue; AppKeyValue = System.Configuration.ConfigurationSettings.AppSettings.Get (AppKey); return AppKeyValue;} catch (Exception ex) {throw ex;}}

// Write public 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 Xelem1; 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");}

See the row that comes from the second method? I originally thought that I can complete the Agreement Russian operation like reading. As a result, unfortunately, I have to write the app.config file as an ordinary XML file. can!

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

New Post(0)