博客园  :: 首页  :: 新随笔  :: 订阅 订阅  :: 管理

C# 读写INI文件

Posted on 2012-09-18 13:35  PHP-张工  阅读(652)  评论(0编辑  收藏  举报
#region INI 读取写入
[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);

private string iniFilePath = Application.StartupPath + "\\public.ini";

/// <summary>
/// 写入INI
/// </summary>
private void IniWrite(string section, string key, string value)
{
	WritePrivateProfileString(section, key, value, iniFilePath);
}

/// <summary>
/// 获取ini
/// </summary>
private string IniRead(string section, string key)
{
	StringBuilder temp = new StringBuilder(255);
	int i = GetPrivateProfileString(section, key, "", temp, 255, iniFilePath);
	return temp.ToString();
}
#endregion