string DBServer = BCPCommon.ReadINI("DB", "DBServer", "", INIPath + "\\BCP.ini");//调用ReadINI方法/*ReadINI方法*/
public static string ReadINI(string section, string key, string def, string filename)
{
StringBuilder temp = new StringBuilder(1024); try
{
GetPrivateProfileString(section, key, def, temp, 1024, filename);//调用GetPrivateProfileString方法
return temp.ToString();
}
catch (Exception ex)
{
throw ex;
}
finally
{
temp = null;
}
}
/*GetPrivateProfileString方法*/
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName
);
/*.ini文件*/
[DB]
DBServer=203.163.38.158
DBName=Northwind
UserID=sa
Password=sa[Path]
BCPOutPath=c:\BCPDemo
BCPInPath=c:\BCPDemo
LogPath=c:\BCPDemo[Flag]
Run=O[Timer]
Interval=100
public static string ReadINI(string section, string key, string def, string filename)
{
StringBuilder temp = new StringBuilder(1024); try
{
GetPrivateProfileString(section, key, def, temp, 1024, filename);//调用GetPrivateProfileString方法
return temp.ToString();
}
catch (Exception ex)
{
throw ex;
}
finally
{
temp = null;
}
}
/*GetPrivateProfileString方法*/
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName
);
/*.ini文件*/
[DB]
DBServer=203.163.38.158
DBName=Northwind
UserID=sa
Password=sa[Path]
BCPOutPath=c:\BCPDemo
BCPInPath=c:\BCPDemo
LogPath=c:\BCPDemo[Flag]
Run=O[Timer]
Interval=100
kernel32是不是这个系统文件有自动解析INI文件的功能?对吗?
---------------
不对...kernel32只是提供了这个API函数...
如果还不是,那他是如何解析的?
还有INI文件必须要是我上面写的那种格式吧。
是不是可以重写GetPrivateProfileString方法来支持更多的INI格式?
key=value
....你应该去看看相关的文档...不过也没什么必要了...除了兼容旧的系统ini已经没有应用的价值...