Solved

urgent

Posted on 2008-10-22
2
220 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

10 Experts available now in Live!

Get 1:1 Help Now