Multiple Excel upload error in ExcelPackage EPPlus

0
 public ActionResult ExcelFile(IEnumerable < HttpPostedFileBase > excelFile) {
   try {
    if (excelFile != null) {
     foreach(var singleExcel in excelFile) {
       string path = "~/ExcelFolder/";
       singleExcel.SaveAs(Server.MapPath(path + singleExcel.FileName));

       using(FileStream fs = new FileStream(Server.MapPath(path + singleExcel.FileName), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
         using(ExcelPackage package = new ExcelPackage(fs)) {
          ExcelWorksheet sheet = package.Workbook.Worksheets[1];

          int startRowNumber = sheet.Dimension.Start.Row;
          int endRowNumber = sheet.Dimension.End.Row;

          int startColumnNumber = sheet.Dimension.Start.Column;
          int endColumnNumber = sheet.Dimension.End.Column;


          if (endColumnNumber > 26) {
           for (int currentColumnNumber = endColumnNumber; startColumnNumber < currentColumnNumber; currentColumnNumber--) {
            var cellValue = sheet.Cells[startRowNumber, currentColumnNumber].Value ? .ToString();

            if (!string.IsNullOrWhiteSpace(cellValue)) {

             if (cellValue == "延人公里小計") {
              sheet.DeleteColumn(currentColumnNumber);
              sheet.Cells[1, currentColumnNumber].Value = "小計";



              //return fsr;

              package.SaveAs(
               new FileInfo(@ "C:\Users\leon0944\Desktop\123\" + singleExcel.FileName));                                           

                break;
               }
              }
             }
            }
           }
          }
         }

Hello,when I upload many Excel to the file then read every single Excel to do someting.then i got error in ExcelPackage package = new ExcelPackage(fs) this row

error message :System.Runtime.InteropServices.COMException: HRESULT: 0x8003001D (STG_E_WRITEFAULT)

sometime is working normally sometime I got error,Please tell me How Can I fix this. The problem existed for several days.

asp.net-mvc
excel
c#-4.0
epplus
asked on Stack Overflow May 15, 2017 by Leon Huang • edited May 15, 2017 by Curiousdev

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0