1

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();
4

1 回答 1

0

将 ExcelDataReader 升级到 3.4.2 版

于 2018-12-13T11:23:50.290 回答