Copy Code code as follows:
Using System;
Using System.Runtime.InteropServices;
Using System.Text;
Using System.IO;
Namespace Common
{
<summary>
INI file read-write class.
</summary>
public class INIFile
{
public string path;
Public INIFile (String INIPath)
{
Path = INIPath;
}
[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 getprivateprofilestring (string section, string key, String Defval, byte[] retVal, int size, stri ng FilePath);
<summary>
Write INI file
</summary>
<param name= "section" ></param>
<param name= "Key" ></param>
<param name= "Value" ></param>
public void Iniwritevalue (string section,string key,string Value)
{
WritePrivateProfileString (Section,key,value,this.path);
}
<summary>
Reading INI file
</summary>
<param name= "section" ></param>
<param name= "Key" ></param>
<returns></returns>
public string Inireadvalue (String section,string Key)
{
StringBuilder temp = new StringBuilder (255);
int i = getprivateprofilestring (Section,key, "", temp, 255, this.path);
Return temp. ToString ();
}
Public byte[] Inireadvalues (string section, string key)
{
byte[] temp = new byte[255];
int i = getprivateprofilestring (section, Key, "", temp, 255, this.path);
return temp;
}
<summary>
Delete all the paragraphs under the INI file
</summary>
public void Clearallsection ()
{
Iniwritevalue (Null,null,null);
}
<summary>
Delete all keys under personal paragraph in INI file
</summary>
<param name= "section" ></param>
public void Clearsection (string section)
{
Iniwritevalue (Section,null,null);
}
}
}
Not too much content, do tricks is still used.