Wrox Programmer Forums
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 12th, 2003, 09:33 PM
Kis Kis is offline
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default INI files


I am new to c#. So can you please tell me how to use INI kind of stuff in c#?

Like i have one INI file
************** abc.ini************
[info]
key=ABC
symbol=logo
value=12

[languages]
009=English
000=french ... etc.
**********************************

It no need to use ini file, file can be of any type. I want to read from this file.

 
Old December 15th, 2003, 10:45 AM
Authorized User
 
Join Date: Nov 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to KABay
Default

Look into using an XML file instead. C# has a very powerful set of classes that allow you to read, search & modify XML 'documents', which are still human readable and editable.
 
Old December 17th, 2003, 05:02 AM
Kis Kis is offline
Registered User
 
Join Date: Dec 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply KABay
But what i though as it is very easy to understand any INI file rather then XML file.
Actualy i want to have something like different Sections, so just use a loop to get al the keys in one section. I don't want to write everything as hard coded. If you can suggests me something for this then :)

Any way i'll try to use XML :)

Thx...

 
Old April 2nd, 2015, 05:04 AM
Registered User
 
Join Date: Apr 2015
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default RE: INI files

Here is a library for both reading and writing INI files in C#.
You can achieve exactly what you have mentioned: "just use a loop to get al the keys in one section"
For example something like this:
Code:
IniFile ini = new IniFile();
ini.Load("abc.ini");

IniSection infoSection = ini.Sections["info"];
foreach (IniKey key in infoSection.Keys)
{
    string keyName = key.Name;
    string keyValue = key.Value;

    // Do something...
}

IniSection languagesSection = ini.Sections["languages"];
foreach (IniKey key in languagesSection.Keys)
{
    string keyName = key.Name;
    string keyValue = key.Value;

    // Do something...
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
browscap.ini ddawson59 BOOK: Beginning ASP 3.0 0 April 17th, 2006 02:15 PM
Reading .ini files anisurr C++ Programming 2 February 7th, 2006 05:02 PM
ini file ptop C++ Programming 0 January 30th, 2006 06:29 AM
How to read and update .INI files using Pure C ?? Poonam C++ Programming 1 March 24th, 2005 01:22 AM
php.ini allang Beginning PHP 1 November 20th, 2003 09:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.