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.
- Create a sample VS.NET (.NET Framework 4.0) Console Application project.
- Add reference to Cinchoo.Core.dll. (Download Cinchoo framework binary here.)
- Use the
Cinchoo.Core.Ini namespace.
- 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.