Disk error while trying to export excel c#

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

c#
.net
epplus
asked on Stack Overflow Apr 12, 2018 by Athira Krishnan • edited Apr 12, 2018 by Christopher H.

2 Answers

0

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

 new ExcelPackage(FileUpload1.PostedFile.InputStream, ""))
answered on Stack Overflow Apr 12, 2018 by Christopher H.
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))

answered on Stack Overflow Apr 12, 2018 by Radderz

User contributions licensed under CC BY-SA 3.0