C# - Import configuration file (.ini)

Asked

Viewed 2,698 times

4

How I import an ini configuration file so that it is loaded and returns with a key value:

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 case it is 'code') and the / method function returns with the value 0.3

Mercy:

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

Structure of the Archive (.ini):

[Seção]
Key=Value
  • I hear it would be with Dllimport and imports User32.dll but it makes no difference!

  • It makes more sense to store the information on app.config...

  • It is a business requirement to import data from an ini file?

  • 1

    i want to upload the file (.ini) of another program and it only supports the configuration file (.ini)

1 answer

6


The idea in and use XML configuration files, so there is no native way to read the files .INI.

That said, and given that sometimes business needs may require the use of a .INI, may use a third-party library to read/write:

(This part brazenly taken from ONLY)

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.