Solved

urgent

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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 …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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