Reputation: 13
I want to take an Excel file form the user and want to read it. I can do it on .net Core project with the first code block below as you see. But I have to run it on a .net Framework project now. I have to fix 2 parts.
First one is IFormFile comes with AspNetCore.Http.Features package. How can I take the file in .net Framework in sameway?
Second one is await file.CopyToAsync(stream);
code block. How I can work it on .net Framework project? Rest of the code is OK I guess.
public void ExcelProducts(IFormFile file)
{
using (var stream = new MemoryStream())
{
await file.CopyToAsync(stream);
using (var package = new ExcelPackage(stream))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
var rowcount = worksheet.Dimension.Rows;
for (int row = 2; row <= rowcount; row++)
{
try
{
...
}
And this is my View.
<div class="text-center">
<div class="container">
<form method="post" action="Market/ExcelProducts" enctype="multipart/form-data">
<input type="file" name="file" />
<button type="submit">Submit</button>
</form>
</div>
</div>
Upvotes: 0
Views: 151