excel导入连接字符串在dll出错的问题
public static DataSet ExcelToDataSet(string fileName)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
string strExcel ="select * from [sheet1$]";
OleDbDataAdapter da = null;
DataSet ds = new DataSet();
try
{
conn.Open();
da = new OleDbDataAdapter(strExcel, strConn);
da.Fill(ds, "sheet1");
}
catch (Exception ex)
{
Console.WriteLine("错误!:" + ex.Message.ToString());
}
finally
{
conn.Close();
conn.Dispose();
}
return ds;
}
这个函数,直接写在asp.net页面就没有问题,excel可以正常访问,但是把这个函数封装到dll时就出错,估计是文件路径错了,fileName是全路径名,在asp.net页面通过HttpContext.Current.Request.PhysicalApplicationPath得到,在dll里要怎么得到这个路径呢?