用C#读写INI文件中,ini文件的名称,我想取相对路径,怎么取?
string path = @"test.ini";
INIFile iniRW = new INIFile(path);
string dir1 = iniRW.INIReadFile("Dir", "Dir1");
string dir2 = iniRW.INIReadFile("Dir", "Dir2");
class INIFile
{
public string Path;
[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);
public INIFile(string strPath)
{
Path = strPath;
}
public string INIReadFile(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.Path);
return temp.ToString();
}
public void INIWriteFile(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.Path);
}
}
这样运行,找不到Test.ini文件,
请帮忙!