Solved

C# ConfigurationManager Write Existing Custom Section

Posted on 2012-04-09
8
397 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

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

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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