public class IniConfigHelp
{
[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);
//ini文件名称
private static string inifilename = "Config.ini";
//CS客户端获取ini文件路径
private static string inifilepath = Application.StartupPath + "\" + inifilename;
//Web端获取ini文件路径
//private static string inifilepath = (Directory.GetCurrentDirectory().ToUpper().IndexOf("IIS") != -1 || Directory.GetCurrentDirectory().ToUpper().IndexOf("C:") != -1) ? HttpRuntime.AppDomainAppPath + "\" + inifilename : Application.StartupPath + "\" + inifilename;
/// <summary>
/// 获取节点的值
/// </summary>
/// <param name="mname">大节点</param>
/// <param name="key">值名称</param>
/// <returns></returns>
public static string GetValue(string mname, string key)
{
StringBuilder s = new StringBuilder(1024);
GetPrivateProfileString(mname, key, "", s, 1024, inifilepath);
return s.ToString();
}
//获取值
String product = IniConfigHelp.GetValue("A", "appid");
}