只有在我将代码部署到服务器上时,才会从代码中获得The directory is not empty
异常。
通过异常调试发现excelReader.Close();
代码如下
IExcelDataReader excelReader = null;
DeleteFile(path);
postedFile.SaveAs(path);
FileStream stream = File.Open(path, FileMode.Open, FileAccess.ReadWrite);
if (Extension.ToLower() == ".xlsx")
{
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
}
else if (Extension.ToLower() == ".xls")
{
excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
}
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
if (result.Tables.Count > 0)
{
dt = result.Tables[0];
}
stream.Close();
stream.Dispose();
DeleteFile(path);
if (excelReader != null)
{
File.AppendAllText(
@"D:\Websites\registry.aan.com\OldAuditLogs\Error.txt",
"excelReader if");
excelReader.Close();
excelReader.Dispose();
}
else {
File.AppendAllText(
@"D:\Websites\registry.aan.com\OldAuditLogs\Error.txt",
"excelReader else");
}
File.AppendAllText(
@"D:\Websites\registry.aan.com\OldAuditLogs\Error.txt",
"excelReader out");
result.Dispose();
答案 0 :(得分:0)
将ExcelDataReader升级到版本3.4.2