Click here to Skip to main content
Click here to Skip to main content
Go to top

Cinchoo - Handling Nested INI Files

, 15 Dec 2012
Rate this:
Please Sign up or sign in to vote.
Way of reading nested INI files

Introduction

Cinchoo is the application framework for .NET. One of the features it exposes is an API to read and write INI file. This article reveals in particular of reading and storing nested INI files. It opens an opportunity to break a large INI file into small manageable sub-documents and use them in your applications.

How to Use

For a sample INI (assume it is a large one) file below:

;This is a test INI file.
 
[PRODUCT]
VERSION=1.002
COMAPNY=NAG Groups LLC
 
[SOFTWARE]
OS1=MAC
OS2=Windows7
 
[ENVIRONMENT]
VERSION=1.0.0.1
PATH=C:\WINDOWS

Here I'm going to show you how you can break them into multiple small files and read them using Cinchoo framework.

MainFile.INI

This main INI file is broken down to two sub INI files. The nested INI files are linked using [INCLUDE] section with path to the INI file as below. The path can be absolute or relative file path.

;This is a test INI file.

[PRODUCT]
VERSION=1.002
COMAPNY=NAG Groups LLC

[INCLUDE("Include1.ini")]
[INCLUDE("Include2.ini")] 

Below are the two broken down INI files:

Include1.ini

[SOFTWARE]
OS1=MAC
OS2=Windows7

Include2.ini

[ENVIRONMENT]
VERSION=1.0.0.1
PATH=C:\WINDOWS 

Well, after having the above XML files, here is how we can load and read them in your application.

  1. Create a sample VS.NET (.NET Framework 4.0) Console Application project.
  2. Add reference to Cinchoo.Core.dll. (Download Cinchoo framework binary here.)
  3. Use the Cinchoo.Core.Ini namespace.
  4. Below is the code to read the above INI file:
static void Main(string[] args)
{
    using (ChoIniDocument iniDocument = ChoIniDocument.Load(@"C:\MainFile.ini"))
    {
        Console.WriteLine(iniDocument.ToString());
    }
} 

That's all folks. Try for yourself. Thanks.

License

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

Share

About the Author

Cinchoo

United States United States
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 16 Dec 2012
Article Copyright 2012 by Cinchoo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid