Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Greetings to you all. While I recently found this article to be of much use in a recent project of mine, I ran into an issue that I know not how to resolve: I cannot seem to find a way to loop through the sections and items of the sections in the INI file -- something which I need to do in order to generate reports about the information contained within.

Now, yes, if the sections were named in an order akin to 0, 1, 2, 3, etc. I could loop through them with ease, alas they cannot be so due to a requirement to which I am bound. Is there any manner that I could use to accomplish my goal?

My thanks in advance,

Logan A. Apple
Posted
Comments
Sergey Alexandrovich Kryukov 21-Feb-15 20:26pm    
Which "this article"? You need to understand that 1) INI format is way too much obsolete and limited, makes little sense, 2) it is so trivial to implement it in .NET where you have nearly everything to do it easily, that using some unknown library might be harder that implementing it from scratch.
—SA
Logan Apple 22-Feb-15 6:08am    
"This" is a link. Indeed, I understand how out of date INIs are, and perhaps I should have simply made a system of my own, but having had used them in the past I found myself wishing to do so now. The library was an implementation that I found simple to use and rather efficient in its ease of use.
Sergey Alexandrovich Kryukov 22-Feb-15 10:14am    
All right, thank you for answering.
I used to explain the detail of possible implementation. You just read it one by one into a dictionary of dictionaries, one by sections others by key, or one dictionary with compound key section-key...
Just in case you need it...
—SA
Logan Apple 22-Feb-15 11:35am    
Thank you. If it becomes necessary, I will use your advice.

Use this one instead: http://inifile.codeplex.com/[^].
Yes, it is written VB.NET, but you can add it as project to your solution, and than simply use it from c#.
 
Share this answer
 
Comments
Logan Apple 22-Feb-15 6:19am    
This is a far more intricate system of manipulation than what I was using. Thank you for pointing me in its direction!
Sergey Alexandrovich Kryukov 22-Feb-15 8:58am    
5ed.
—SA
Hi Logan, I presume that by now you have already achieved this task, but nevertheless I wanted to inform you that I have a C# library for INI files on GitHub which you can feel free to use.
For example here is how could iterate through all the sections and all the sections's keys:
C#
IniFile ini = new IniFile();
ini.Load("path to your .ini file ...");

foreach (IniSection section in ini.Sections)
{
    foreach (IniKey key in section.Keys)
    {
        string sectionName = section.Name;
        string keyName = key.Name;
        string keyValue = key.Value;

        // Do something ...
    }
}

Note that the library even supports some more complex tasks out of the box (like compression, encryption, binding, serializing, etc.). Also in case you do decide to try it out sometime note that you can contact me if you need any help with it by posting a reply to this[^] post.
 
Share this answer
 
Comments
Logan Apple 16-Jun-15 6:01am    
Indeed, this has long since been resolved, but I thank you for sharing this library with me! I may well make use of it in the future.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900