如何在C#中读取App.config [英] How read App.config in C#
本文介绍了如何在C#中读取App.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想阅读这个app.config值
I want to read this app.config values
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="LibrarySetting" type="LibraryConfigUtilities.ConfigurationSectionHandler, LibraryConfigUtilities" />
</configSections>
<LibrarySetting>
<Country Culture="tr-TR" Currency="TRY" DailyPenaltyFee="5,25" PenaltyAppliesAfter="3">
<WeekendSetting>
<Weekend Day="6"/>
<Weekend Day="0"/>
</WeekendSetting>
<HolidaySetting>
<Holiday Date="25.11.2009"/>
<Holiday Date="26.11.2009"/>
<Holiday Date="27.11.2009"/>
</HolidaySetting>
</Country>
<Country Culture="ar-AE" Currency="AED" DailyPenaltyFee="8.00" PenaltyAppliesAfter="4">
<WeekendSetting>
<Weekend Day="5"/>
<Weekend Day="6"/>
</WeekendSetting>
<HolidaySetting>
<Holiday Date="25.11.2009"/>
<Holiday Date="26.11.2009"/>
<Holiday Date="27.11.2009"/>
</HolidaySetting>
</Country>
</LibrarySetting>
</configuration>
推荐答案
您需要在参考文献中添加对System.Configuration
的引用文件夹。
然后使用< code>
ConfigurationManager类。
另外请参阅如何从应用程序获取连接字符串。在C#中配置 [ ^ ]作为附加参考。
You'll need to add a reference toSystem.Configuration
in your references folder.
Then use the<code>
ConfigurationManager class.
Also refer to How to get Connection String from App.Config in C#[^] as an additional reference.
这篇关于CodeProject的文章应该有所帮助。
app.config或web.config中的自定义配置部分 [ ^ ]
This article on CodeProject should help.
Custom Configuration Sections in app.config or web.config[^]
试试这个
Try this
XElement root = XElement.Load("your app config path"); //
var topnode = root.Elements("LibrarySetting").Descendants<XElement>("Country").ToList();
var DailyPenaltyFees = topnode.Attributes("DailyPenaltyFee").Select(k => k.Value).ToList();
这篇关于如何在C#中读取App.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文