C# Read And Write Config Files

Posted on by admin

JPrinz 24-Oct-08 5:0424-Oct-08 5:04How can I change an app.config file programmaticaly with Configuration Manager with SingleTagSectionHandler. Edw76 15-Oct-08 6:5815-Oct-08 6:58Alois,Your code under the 'Is this new mechanism compatible with the old one?' Paragraph helped me a lot!! Thank you!1) The only problem that I'm having is group.IsDeclared always returns false although I believe I declared the section group correctly in my app.config file:However, section.SectionInformation.IsDeclared returns true.2) Also, the group names and section names are not returned in the order in which they are declared in the config file, which is not a big deal as long as all of them are being returned, I was just wondering why that's the case.Thanks for any comments.Eve. Figmo2 7-Oct-08 9:047-Oct-08 9:04I tried this.System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);config.AppSettings.Settings'PlayGames'.Value = 'False';config.Save(ConfigurationSaveMode.Modified);this.Close; //.close main form and terminate appAnd could not get it to work. But it would never change the setting to 'False'. It was as if the above code was doing nothing.So I opened the.config file in the editor and left it open as I ran my app.

Write

C-reactive Protein

What I saw confuses me.As I close the form (and execute the above code) I get TWO prompts from VS2008 telling me that the file was modified outside the editor, would I like to reload it.When I answer yes to the first prompt, my config file is replaced by this HUGE ASS XML FILE that has settings in there for all kinds of stuff that I have no clue what they mean. 576 lines long to be exact - compared to the 17 lines that were in there before I stared. But in there, I can indeed see my section and indeed the value of 'PlayGames' has been changed to false.When I answer yes to the second prompt, my config file is replaced by a copy of the original. All the extra settings that I have no clue what they are are gone. It looks EXACTLY THE SAME as before I ran my app.

C-diff

17 lines long again. And all data restored to original value. Including the value of 'PlayGames' - back to being true (the original value)I have tried answering YES to the first prompt, and NO to the second prompt. Then saving the file.

Thus leaving the huge.config file on the disk when I run the app again. Sure enough, 'PlayGames' is false like it should when I start my app. But when I exit (and execute the above code) the.config file reverts back to the original 17 line version (and all data is restored to that version as well).Can somebody clue me in as to what the hell is going on here? It's like it's copying the original app.config from my source folder to the bin folder on exit. How do I stop it?

ConfigParserConfigParser - is a slim, cross-platform, fully managed C# library for reading and writing.ini,.conf,.cfg etc configuration files.You could use it in your, (iOS & Android),.NET Framework applications (even with old 4.0/4.5),.NET Core CLI and ASP.NET Core applications, etc Features Customization. customizable encoding (most encodings can be auto-detected). customizable culture.

customizable number styles (e.g. Currencies, exponential notation etc). customizable line endings (usually auto-detected). customizable true and false (e.g. Dotnet test tests LicenseConfigParser is distributed under the, which grants you.

Private use. Commercial use.

Modification. DistributionHowever you have to include the content of file in your source code (if you distribute your Software in text form), otherwise include it in your own LICENSE file or to some sort of About - Open-source libraries section if you distribute your Software as a compiled library / binary.Here is why (part of ): The above copyright notice and this permission noticeshall be included in all copies or substantial portions of the Software.