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
Solved

C# ConfigurationManager Write Existing Custom Section

Posted on 2012-04-09
8
395 Views
Last Modified: 2012-12-07
So I have an application that I need to have a portable configuration file for.  I have started using the ConfigurationManager object for this, and have gotten it to read an existing Custom Section, and even create a default one if there is no Custom Section meeting my name, but I can't seem to figure out how to be able to write changed values to an existing Custom Section using ConfigurationManager.  I would like to allow the user to update values as needed without editing the .config XML directly, and so far I only see that I can do this using the AppSettings section.  Anyone have an idea of how to do this using ConfigurationManager?
0
Comment
Question by:MonMusc
  • 5
  • 3
8 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 37823934
you probably using something like:

 SectionType st = (SectionType)onfigurationManager.GetSection(“<section>”);

where  SectionType is your custom section wrapper class.
if you create the properties with both get and set you should be able to update your custom sections.
0
 

Author Comment

by:MonMusc
ID: 37829176
So looking at that, I would assume the thinking is that using the GetSection will create a object based on the App.Config CustomSection, and if I do a set to the property it will store it?  I'm curious because I specifically have to do an AddSection to do the initial write, but alas I will give it a shot and see if this leads me down the right path.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 37831226
post the config and wrapper class for the custom section and i'll take a look
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:MonMusc
ID: 37840939
Attached is the cs and config file.
Config.cs
App.config
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 37847790
in your app config you have a whitespace instead of underscore in the config section type attribute.

current:
type="License_Reporter.ConfigSection, License Reporter, ...

should be:
type="License_Reporter.ConfigSection, License_Reporter, ...
0
 

Author Comment

by:MonMusc
ID: 37851212
Didn't think about that, it's working though so wondering if white space really bothers it much...
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 37851311
License_Reporter is the name of the project/dll so it does matters.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38670856
any specific reason for grading this as B?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…

840 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