C # - Import configuration file (.ini)

4

How do I import an ini configuration file so that it loads and returns a value of one key:

Example:

[version]
code=0.3

The program will load the ini file and I select the section (in case it is 'version'), select the key (in the case it is 'code') and the function / method returns with value 0.3

Method:

var strCode = GetStringFromFile("atualiza.ini", "version", "code");

File Structure (.ini):

[Seção]
Key=Value
    
asked by anonymous 23.10.2014 / 02:09

1 answer

5

The idea at and use so there is no native way of reading the .INI files.

Given this, and since sometimes business needs may require the use of .INI , you can use a third-party library to read / write:

(This blatantly taken from SO )

You can also follow one of these tutorials that explains how to use the kernel32 DLL to read and write a .INI file:

23.10.2014 / 10:52