.net操作InI文件

public class INI
{

 public static string IniFileName = "";//路径

 

[DllImport("kernel32")]
private static extern int GetPrivateProfileInt(string lpApplicationName, string lpKeyName, int nDefault, string lpFileName);
[DllImport("kernel32")]
private static extern bool GetPrivateProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
[DllImport("kernel32")]
private static extern bool WritePrivateProfileString(string lpApplicationName, string lpKeyName, string lpString, string lpFileName);
[DllImport("kernel32")]
private static extern bool GetPrivateProfileSection(string lpAppName, string lpReturnedString, int nSize, string lpFileName);
[DllImport("kernel32")]
private static extern bool WritePrivateProfileSection(string lpAppName, string lpString, string lpFileName);

public void WriteValue(string Section,string Key,string Value)//对ini文件进行写操作的函数
{
WritePrivateProfileString(Section, Key, Value, IniFileName);
}

public string ReadValue(string Section, string Key)//对ini文件进行读操作的函数
{
StringBuilder temp = new StringBuilder(50000);
bool b = GetPrivateProfileString(Section, Key, "", temp, temp.Capacity, IniFileName);
return temp.ToString();
}

 

}

posted @ 2016-12-12 10:59  ■乐  阅读(466)  评论(0编辑  收藏  举报