using System;
using System.Text;
using System.Runtime.InteropServices;

class INIFile
{
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(String Section, String Key, String Value, String FilePath);
[DllImport("kernel32")]
private static extern Int32 GetPrivateProfileString(String Section, String Key, String Definition, StringBuilder Return, Int32 Size, String FilePath);

private String FilePath = String.Empty;

public INIFile(String FilePath)
{
this.FilePath = FilePath;
}

public String this[String Key]
{
get
{
return this["Default", Key];
}
set
{
this["Default", Key] = value;
}
}

public String this [String Section, String Key]
{
get
{
StringBuilder Temp = new StringBuilder(255);
GetPrivateProfileString(Section, Key, "", Temp, 255, this.FilePath);
return Temp.ToString();
}
set
{
WritePrivateProfileString(Section, Key, value, this.FilePath);
}
}
}


You do not need to create/read/write anything! All you need to do is use the class, the ini file will create itself, update itself, and read itself on command.

Allows you to create and use ini setting files for configuration.

Example Usage;
INIFile Temp = new INIFile("C:\\Test.ini");
Temp["width"] = 10;


That will automatically create the ini, and update the ini data, readable at next program entrance.