SIGN UP MEMBER LOGIN:    
ARTICLE

INI File Class in C#

Posted by Aaron Bregger Articles | Visual C# February 26, 2008
This is a simple and easy to implement class for handling a .INI file. It uses the standard INI text file format to read and save settings.
Reader Level:
Download Files:
 

The .INI file format is a simple way to store settings in a easy to edit format. I have created a simple set of classes used to parse and save .INI files. It uses Dictionaries for easy key based access of parameters and sections. The standard rules for .INI are used for parsing, however the ini format is essentially one long text file and variations do occur.

Included is the source and binaries to the INIFile and a testing program I developed. There is also an example testing INI file that uses every feature that the class offers.

Example:

ini.Sections["test1"].Parameters.Add("Test4", "dolphins");
//or
ini["test1", "Test2"] = "Success!";

Login to add your contents and source code to this article
share this article :
post comment
 

included example doesn't show how to pull individual values from the ini. something such as

Variable = ini.Section["AppSettings"].Parameter["Value"];

or other similar options...

Posted by Chris Werner Feb 11, 2010

You can use the getter and setter in value = ini["section", "parameter"] and it acts almost like a 2D array.

Posted by Aaron Bregger Jan 20, 2010

Hi, Can you post some examples on how to use this?

Posted by Deepta Shrestha Apr 14, 2009
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor