简体   繁体   English

如何通过代码将自定义configSections添加到app.config文件

[英]how to add custom configSections to app.config file through code

How can I add sections to an app.config file through code? 如何通过代码将部分添加到app.config文件?

Something like this in my config file, but it can have multiple sections but not through appSettings as I would like to add multiple values to it. 我的配置文件中有类似的内容,但是它可以有多个部分,但不能通过appSettings进行,因为我想向其中添加多个值。

<configSections>
 <!-- CUSTOM CONFIG SECTIONS BELOW -->
 <section name="EmailSection" type="Email.EmailSection, Email" />
</configSections>

<EmailSection>
 <Emails>
  <email id="HOST" name="mail.somedomain.com" />
  <email id="PORT" name="25" />
  <email id="TOADDRESS" name="" />
  <email id="FROMADDRESS" name="dev@somedomain.com" />
 </Emails>
</EmailSection>

I would like to do this through an import method in my code so i can select an xml file which will then add the sections to my app.config. 我想通过代码中的导入方法来执行此操作,因此我可以选择一个xml文件,然后将这些部分添加到我的app.config中。

Regards 问候

Aidan 艾丹

Managed to get this working through this . 设法通过这个解决这个问题

I had to loop through my items and add them in, but does what I need it. 我必须遍历所有项目并将其添加进去,但是可以满足我的需要。

Thanks for the advice though. 谢谢你的建议。

Aidan 艾丹

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在同一App.Config中使用ConnectionStrings和自定义ConfigSections - Using ConnectionStrings and custom ConfigSections in the same App.Config app.config configSections自定义设置无法找到架构信息 - app.config configSections custom settings can not find schema information 从App.Config文件的configSections获取节名 - Getting section name from configSections on App.Config file 在 WPF 中,如何绑定到 app.config 中 configSections 中的设置? - In WPF how can I bind to settings in configSections in app.config? 如何在 app.config xml 文件中添加 Gitlab 自定义变量 - How to add Gitlab custom variable in app.config xml file 这是什么 <location> 中提到的元素 <configSections><section> 在app.config中 - What is this <location> element referred to in <configSections><section> in app.config 从不同应用程序的App.Config的configSections中访问值 - Accessing Values from configSections of App.Config of different application C#.Net:如何通过.net代码读取App.config中定义的跟踪文件路径? - C#.Net : How to read trace file path defined in App.config through .net code? 如何在Visual Studio Code中添加App.Config? - How to add an App.Config in Visual Studio Code? 我应该在app.config中添加自定义部分吗? 如果是这样,怎么办? - Should I add a custom section to app.config? If so, how?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM