【问题标题】:How to read custom config section in app.config in c#如何在 c# 中读取 app.config 中的自定义配置部分
【发布时间】:2012-01-28 10:24:08
【问题描述】:

我想从 app.config 中阅读以下自定义部分:

<StartupFolders>    
   <Folders name="a">
      <add folderType="Inst" path="c:\foo" />
      <add folderType="Prof" path="C:\foo1" />      
   </Folders>
   <Folders name="b">
      <add folderType="Inst" path="c:\foo" />
      <add folderType="Prof" path="C:\foo1" />      
   </Folders> 
</StartupFolders>

我找到了this link,但它没有说多个&lt;Folders&gt; 标签。请帮忙?

【问题讨论】:

  • 请发布您的代码并解释它如何不适合您。就目前而言,这是一个质量很差的问题,应该关闭。
  • 您是否查看了我在回答您之前的问题时发布的一些链接? stackoverflow.com/questions/8642247/… 这些链接也将解释如何编写自定义配置部分以及如何阅读和使用它

标签: c# app-config configsection


【解决方案1】:

您好,您可以像这样访问自定义部分

CustomConfigClass section = (CustomConfigClass)ConfigurationManager.GetSection("StartupFolders");

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2012-10-04
    • 2011-11-21
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    • 2016-05-02
    相关资源
    最近更新 更多