丈夫欲遂平生志,一载寒窗一举汤。这篇文章主要讲述修改App.config的键和值相关的知识,希望能为你提供帮助。
App.config中内容:
< ?xml version="1.0" encoding="utf-8" ?> < configuration> < !--< system.windows.forms jitDebugging="true"//允许调试/> --> < appSettings> < add key="setInterval" value="https://www.songbingjia.com/android/1000"/> < add key="chooseCOM" value="https://www.songbingjia.com/android/COM4"/> < add key="senStr" value="https://www.songbingjia.com/android/R"/> < /appSettings> < /configuration>
【修改App.config的键和值】读取App.config中chooseCOM内容,并把COM4改为COM1:
string setCOM = ConfigurationSettings.AppSettings["chooseCOM"]; ConfigHelper.SetValue("chooseCOM","COM1"); //
设置app.config键值的方法:
public static class ConfigHelper { public void SetValue(String AppKey, String 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"); } }
推荐阅读
- Problem E: 编写函数(Swap (I) (Append Code))
- AndroidGetAPKInfo --- 检查包名(packageName)版本(versionNameversionCode)应用签名(Signature)等信息
- 安卓SharedPreferences
- 20200628-关于Android
- vue : 无法加载文件 C:UsersxxxAppDataRoamingpmvue.ps1,因为在此系统上禁止运行脚本
- uni-app 缓存无法读取问题
- from absl import app, flags, logging
- Android ContentProvider:数据共享
- Sass和SCSS的区别比较