Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

urgent

Posted on 2008-10-22
2
Medium Priority
?
224 Views
Last Modified: 2013-12-17
need help  Reading custom configuration section in app.config file in visual studio 2008 using c#
here is the code
app.config
               <Cdefault>
                       <items name="Public">
                  <item name="SleepSeconds" value="60000" />
                  <item name="heartbeatMinutes" value="5" />
                  <item name="AppVersion" value ="1.1.20051219" /
                  <item name="logLevel" value="DEBUG" />    
                  <item name="UseProxy" value="true" />
        </items>

c# code
    SecuredProfile configuration = ConfigurationManager.GetProfile("MaximoPagingService");
SecuredProfile configuration = ConfigurationManager.GetProfile(context[ContextKeys.Application].ToString());
                  
if (configuration.Contains("SleepSeconds"))
_sleepSeconds = System.Convert.ToInt32(configuration.GetItem("SleepSeconds").Value);



0
Comment
Question by:Swetha_aJaX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 1500 total points
ID: 22783130
you need to follow these steps

Define your Custom Configuration Class
you need to define class, which inherit from System.Configuration.ConfigurationSection, and add a property per setting you wish to store
using System;
using System.Configuration;

public class BlogSettings : ConfigurationSection
{
  private static BlogSettings settings
    = ConfigurationManager.GetSection("BlogSettings") as BlogSettings;
       
  public static BlogSettings Settings
  {
    get
    {
      return settings;
    }
  }

  [ConfigurationProperty("frontPagePostCount"
    , DefaultValue = 20
    , IsRequired = false)]
  [IntegerValidator(MinValue = 1
    , MaxValue = 100)]
  public int FrontPagePostCount
  {
      get { return (int)this["frontPagePostCount"]; }
        set { this["frontPagePostCount"] = value; }
  }


  [ConfigurationProperty("title"
    , IsRequired=true)]
  [StringValidator(InvalidCharacters = "  ~!@#$%^&*()[]{}/;\"|\\"
    , MinLength=1
    , MaxLength=256)]
  public string Title
  {
    get { return (string)this["title"]; }
    set { this["title"] = value; }
  }
}

2. Add your new configuration section to web.config or app.config

<configuration>
  <configSections>
      <section name="BlogSettings" type="Fully.Qualified.TypeName.BlogSettings,  
      AssemblyName" />
  </configSections>
  <BlogSettings
    frontPagePostCount="10"
    title="Youve Been Haacked" />
</configuration>

3. use your new custom configuration section
string title = BlogSettings.Settings.Title;
msessagebox.show(title); //it works!!!


also refer some good artical
http://devlicio.us/blogs/derik_whittaker/archive/2006/11/13/app-config-and-custom-configuration-sections.aspx
http://www.codeproject.com/KB/aspnet/ConfigSections.aspx
0
 

Author Closing Comment

by:Swetha_aJaX
ID: 31509078
thanks for the reply it really helped me out
0

Featured Post

URL rewriting in AWS CloudFront

A quick how-to guide to implement with a Lambda function!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question