In an ASP.NET MVC Core (.netcore2) application, I'm using the following method to read an Excel file.
[HttpPost]
public IActionResult Import (IFormFile importFile)
{
using (var excel = new ExcelPackage(importFile.OpenReadStream())
{
var sheet = excel.Workbook.Worksheets.FirstOrDefault();
if (sheet == null) return BadRequest("No worksheet.");
var events = /* import logic */
return Json(events);
}
}
However, epplus is throwing this exception:
COMException: A disk error occurred during a write operation. (Exception from HRESULT: 0x8003001D (STG_E_WRITEFAULT))
I've used methods like this in the past to import Excel files, and I don't know what's going wrong.
I've checked:
Epplus currently has an issue when targeting .NetStandard
with text encoding. To resolve this, add this reference to your project.
<ItemGroup>
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.4.0" />
</ItemGroup>
Then, call this once in your application's startup -
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
More detail here on why this is happening.
User contributions licensed under CC BY-SA 3.0