Solved

urgent

Posted on 2008-10-22
2
217 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
2 Comments
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 500 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now