Using System;
Using System. Text;
Using System. Runtime. InteropServices;
Namespace Pub. Class
{
/// <Summary>
/// INI File Operation
/// </Summary>
Public class IniFile
{
# Region private member
Private string path;
[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 );
# Endregion
# Region Constructor
/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "INIPath"> file name </param>
Public IniFile (string INIPath) {path = INIPath ;}
# Endregion
# Region WriteValue
/// <Summary>
/// Write data to the INI File
/// </Summary>
/// <Param name = "Section"> node </param>
/// <Param name = "Key"> name </param>
/// <Param name = "Value"> Value </param>
Public void WriteValue (string Section, string Key, string Value)
{
WritePrivateProfileString (Section, Key, Value, this. path );
}
# Endregion
# Region ReadValue
/// <Summary>
/// Read data to the INI File
/// </Summary>
/// <Param name = "Section"> node </param>
/// <Param name = "Key"> name </param>
/// <Returns> data </returns>
Public string ReadValue (string Section, string Key)
{
StringBuilder temp = new StringBuilder (255 );
Int I = GetPrivateProfileString (Section, Key, "", temp, 255, this. path );
Return temp. ToString ();
}
# Endregion
}
}