?
Solved

Read INI file

Posted on 2011-03-03
5
Medium Priority
?
680 Views
Last Modified: 2012-05-11
Can someone tell me how to read an in file that has multiple values in each section from within a windows application  ?


e.g
[Servers]
ServerName 1=Server1
ServerName 2=Server2
ServerName 3=Server3
0
Comment
Question by:martin05
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 35030337
0
 

Author Comment

by:martin05
ID: 35030734
rawinnlnx9 thanks for the reply thats fine I can read the ini file for a single value, but how do you do it for multiple values ?


 INIFile ini = new INIFile("C:\\config.ini");

            for (int i = 0; i < ??????????; i++)
            {
                ini.Read ??("Server 1,???????????")
            }

0
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 1000 total points
ID: 35033419
0
 
LVL 8

Assisted Solution

by:cubaman_24
cubaman_24 earned 1000 total points
ID: 35035441
Hello:
In .Net is more common to use xml configuration files instead of INI files. And there is an API to handle it.

http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx#Y432

best regards.
// Get the AppSettings section.        
// This function uses the AppSettings property
// to read the appSettings configuration 
// section.
public static void ReadAppSettings()
{
  try
  {
    // Get the AppSettings section.
    NameValueCollection appSettings =
       ConfigurationManager.AppSettings;

    // Get the AppSettings section elements.
    Console.WriteLine();
    Console.WriteLine("Using AppSettings property.");
    Console.WriteLine("Application settings:");

    if (appSettings.Count == 0)
    {
      Console.WriteLine("[ReadAppSettings: {0}]",
      "AppSettings is empty Use GetSection command first.");
    }
    for (int i = 0; i < appSettings.Count; i++)
    {
      Console.WriteLine("#{0} Key: {1} Value: {2}",
        i, appSettings.GetKey(i), appSettings[i]);
    }
  }
  catch (ConfigurationErrorsException e)
  {
    Console.WriteLine("[ReadAppSettings: {0}]",
        e.ToString());
  }
}

Open in new window

0
 

Author Closing Comment

by:martin05
ID: 35067135
I got 2 different solutions to my problem .
Both will work so splitting the points

Thanks for your help guys
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question