[英]How to modify/update custom config section of app.config using c#
I am trying to save some configurations in app.config for my windows application. 我正在尝试为Windows应用程序在app.config中保存一些配置。 I searched in Google for solution but not anything related to this.
我在Google中搜索了解决方案,但没有与此相关的任何内容。 My requirement is I want to save/update the configurations in app.config using my windows application.
我的要求是我想使用Windows应用程序在app.config中保存/更新配置。
My schema will be like this: 我的架构将如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="customAppSettings1" type="System.Configuration.NameValueSectionHandler"/>
<section name="customAppSettings2" type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<customAppSettings1>
<add key="FirstKey" value="1" />
<add key="SecondKey" value="2" />
</customAppSettings1>
<customAppSettings2>
<add key="FirstKey" value="1" />
<add key="SecondKey" value="2" />
</customAppSettings2>
</configuration>
This code is giving changed custom values. 此代码提供了更改的自定义值。 but not saving on physical file.
但不保存在物理文件上。 A bit progress in your question.
您的问题有所进步。
var xmlDoc = new XmlDocument();
xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
xmlDoc.SelectSingleNode("//applicationSettings/MyApp_Application.Properties.Settings/setting/value").InnerText = "server=127.0.0.1;uid=root;pwd=root;database=" + comboBox1.SelectedItem.ToString();
xmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
ConfigurationManager.RefreshSection("applicationSettings/MyApp_Application.Properties.Settings/setting");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.