Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to read this app.config values

XML
<?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>
Posted
Comments
S Houghtelin 4-Feb-14 15:18pm    
Two members have given you valid resources for you to use to figure out how to read a configuration file.

Demanding code from people who are generously giving their time to assist you will only result in your query and your member account being marked as abusive.

Read the articles carefully, try using some of the examples shown in the articles. Then show what you have tried and we can help you.

You'll need to add a reference to System.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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Feb-14 12:25pm    
Sure, a 5.
—SA
Abhinav S 4-Feb-14 12:25pm    
Thank you SA.
Simon Lee Shugar 4-Feb-14 12:31pm    
Beat me to it :)
Member 9522119 4-Feb-14 12:29pm    
I want to read "DailyPenaltyFee" but your articles didnt help me
Sergey Alexandrovich Kryukov 4-Feb-14 14:38pm    
Okay, very nice, you got an abuse report for laziness and failure to use the help... :-)
—SA
This article on CodeProject should help.

Custom Configuration Sections in app.config or web.config[^]
 
Share this answer
 
Comments
Member 9522119 4-Feb-14 12:29pm    
I want to read "DailyPenaltyFee" but your articles didnt help me
Try this

C#
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();
 
Share this answer
 
Comments
aykutozturk 19-Jan-17 6:46am    
What is the XElement
Karthik_Mahalingam 20-Jan-17 0:49am    
its a class
aykutozturk 20-Jan-17 11:41am    
I don't understand what XElement class doing.Can you explain XElement class?
Karthik_Mahalingam 31-Jan-17 1:52am    
refer this
https://msdn.microsoft.com/en-us/library/system.xml.linq.xelement(v=vs.110).aspx
its a library for working with xml

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900