0

I am trying to export an excel file using EPPlus

   if (FileUpload1.HasFile && Path.GetExtension(FileUpload1.FileName) == ".xlsx")
        {

            bo.ExcelFile = txtFileName.Text;
            bo.ExcelFileBranch = txtBranchName.Text;
            bo.ExcelFileFromDate = txtValidFrom.Text;
            bo.ExcelFileToDate = txtValidTo.Text;

            using (var excel = new ExcelPackage(FileUpload1.PostedFile.InputStream))
            {
                var tbl = new DataTable();
                var ws = excel.Workbook.Worksheets.First();               


                var hasHeader = false;  // adjust accordingly
                // add DataColumns to DataTable
                foreach (var firstRowCell in ws.Cells[1, 1, 1, ws.Dimension.End.Column])
                    tbl.Columns.Add(hasHeader ? String.Format("Column {0}", firstRowCell.Start.Column)
                        : firstRowCell.Text);

                // add DataRows to DataTable
                int startRow = hasHeader ? 1 : 2;
                for (int rowNum = startRow; rowNum <= ws.Dimension.End.Row; rowNum++)
                {
                    var wsRow = ws.Cells[rowNum, 1, rowNum, ws.Dimension.End.Column];
                    DataRow row = tbl.NewRow();
                    foreach (var cell in wsRow)
                        row[cell.Start.Column - 1] = cell.Text;
                    tbl.Rows.Add(row);
                }

But i am getting the following error :

(Exception from HRESULT: 0x8003001D (STG_E_WRITEFAULT))"- Disk error occured during write operation

Software Dev
  • 5,368
  • 5
  • 22
  • 45

2 Answers2

0

Not sure but try to read the excel file using a blank password :

 new ExcelPackage(FileUpload1.PostedFile.InputStream, ""))
Software Dev
  • 5,368
  • 5
  • 22
  • 45
  • Try this code shown "An exception of type 'System.Exception' occurred in EPPlus.dll but was not handled in user code Additional information: The stream must be read/write – Athira Krishnan Apr 12 '18 at 11:22
0

This could relate to several problems. A couple of different solutions have been suggested here:

A disk error occurred during a write operation. (Exception from HRESULT: 0x8003001D (STG_E_WRITEFAULT))

Radderz
  • 2,770
  • 4
  • 28
  • 40