C# 读写INI文件类

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Runtime.InteropServices;


public class IniFile
{
public string path; //INI文件名

//声明读写INI文件的API函数
[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);

/// <summary>
/// 类的构造函数
/// </summary>
/// <param >INI文件名</param>
public IniFile(string INIPath)
{
path = INIPath;
}

/// <summary>
/// 写INI文件
/// </summary>
/// <param >节</param>
/// <param >关键字</param>
/// <param >值</param>
public void WriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.path);
}
/// <summary>
/// 读取INI文件指定
/// </summary>
/// <param >节</param>
/// <param >关键字</param>
/// <returns>指定节-关键字的值</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();
}
}

你可能感兴趣的:(C++,c,UI,Web,C#)