用C#读写INI文件中,ini文件的名称,我想取相对路径,怎么取?

Snow780311 2006-05-19 08:26:29
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文件,
请帮忙!
...全文
587 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Anders_lt 2006-05-19
  • 打赏
  • 举报
回复
1 filePath=@"D:\test.ini";
2 属性:System.Windows.Forms.Application.StartupPath
marvelstack 2006-05-19
  • 打赏
  • 举报
回复
http://www.codeproject.com/csharp/readwritexmlini.asp
Mittermeyer 2006-05-19
  • 打赏
  • 举报
回复
这样写就行了:
path = System.IO.Path.Combine(Application.StartupPath,"test.ini");
chinawn 2006-05-19
  • 打赏
  • 举报
回复
Application.StartupPath + @"\Test.ini"))试下

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧