C# 读取INI

#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();
}
posted @ 2013-06-24 10:00  小毛驴  阅读(168)  评论(0编辑  收藏  举报