ini file

S

Sphinx

Hi

I'm trying to make a project where I have to read from an ini file the keys
and values of several sections.
example:
[Section 1]
key1 = ala-lab
key2 = ala-amf
key3 = ala-ima

[Section 2]
key1 = ci-rep
key2 = ci-rdl
key3 = ci-rep

....

Does anyone know how to do this? I really don't have any idea.

tia,
Sphinx
 
H

Henk Verhoeven

This may help you

[DllImport("kernel32")]

private static extern long WritePrivateProfileString(string section,

string key,string val,string filePath);

[DllImport("kernel32")]

private static extern int GetPrivateProfileString(string section,

string key,string def, StringBuilder retVal,

int size,string filePath);

[DllImport("kernel32")]

private static extern int SearchPath(string path,

string fileName,string fileExt,int bufSize, StringBuilder buffer,

string filePart);

[DllImport("kernel32")]

private static extern int GetLastError();



You will find a ton of implementations around INI files If you search the
opersource or community sites, (www.codeproject.com example)

Hope it helps

henk
 
G

Gerry O'Brien [MVP]

If you're not familiar with using API calls, you can also the StreamReader
and StreamWrite objects to open and read the text files. You can then use
the various text parsing methods to search for the section headings and
locate values by parsing the text file.

--
Gerry O'Brien
Visual Developer .NET MVP



Henk Verhoeven said:
This may help you

[DllImport("kernel32")]

private static extern long WritePrivateProfileString(string section,

string key,string val,string filePath);

[DllImport("kernel32")]

private static extern int GetPrivateProfileString(string section,

string key,string def, StringBuilder retVal,

int size,string filePath);

[DllImport("kernel32")]

private static extern int SearchPath(string path,

string fileName,string fileExt,int bufSize, StringBuilder buffer,

string filePart);

[DllImport("kernel32")]

private static extern int GetLastError();



You will find a ton of implementations around INI files If you search the
opersource or community sites, (www.codeproject.com example)

Hope it helps

henk

Sphinx said:
Hi

I'm trying to make a project where I have to read from an ini file the keys
and values of several sections.
example:
[Section 1]
key1 = ala-lab
key2 = ala-amf
key3 = ala-ima

[Section 2]
key1 = ci-rep
key2 = ci-rdl
key3 = ci-rep

...

Does anyone know how to do this? I really don't have any idea.

tia,
Sphinx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top