?
Solved

C# ConfigurationManager Write Existing Custom Section

Posted on 2012-04-09
8
Medium Priority
?
399 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
[X]
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
  • 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
AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

 

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 1500 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 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