Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

urgent

Posted on 2008-10-22
2
Medium Priority
?
225 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 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

926 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