Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Read INI file

Posted on 2011-03-03
5
Medium Priority
?
682 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

597 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