c#关于查找文件相对路径的问题

来源:百度知道 编辑:UC知道 时间:2024/05/20 16:37:03
string filename = "C:\\Documents and Settings\\Administrator\\桌面\\用户信息表.xls";

上面那个excel表的路径怎么改成与应用程序EXE相同的路径
快救命啊

string filename = Application.StartupPath+“\\用户信息表.xls”;
我的回答不符合吗?
楼上你的路径错了,你那种取法,不是绝对限定路径,是当年运行程序的路径,也就是如果我另一个程序调用楼主的程序,楼主程序放在D:\\,我的程序在C:\\运行,那么用System.Environment.CurrentDirectory取出来的就是"C:\\",
而我的Application.StartupPath取出来的永远是D:\\

string path = System.IO.Path.Combine(System.Environment.CurrentDirectory,"用户信息表.xls");