File Stream

Hello,

After migrating to version 21.2.6 my upload stopped working. I have tried all the sample codes but have not been successful.

I don't need to store the file, just read it.

current code:


 <SfUploader @ref="Upload" AllowMultiple="false" ShowFileList="false" AllowedExtensions=".xlsx" MaxFileSize=2000000>

<UploaderEvents ValueChange="UploadFileChange" />

</SfUploader>


private void UploadFileChange(UploadChangeEventArgs args) {

foreach (var file in args.Files)
{

using (ExcelEngine excelEngine = new ExcelEngine())

{

IApplication application = excelEngine.Excel;

application.DefaultVersion = ExcelVersion.Xlsx;


var filestream = file.Stream;

filestream.Seek(0, SeekOrigin.Begin);


IWorkbook workbook = application.Workbooks.Open(filestream);

file.Stream.Close();

IWorksheet worksheet = workbook.Worksheets[0];

var table = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames);

foreach (System.Data.DataRow row in table.Rows)
{

}

}

}

  • BlazorWebAssembly
  • dotnet 7.0
  • Syncfusion 21.2.6

thanks

5 Replies 1 reply marked as answer

SP Sureshkumar P Syncfusion Team May 26, 2023 08:40 AM UTC

Hi Anderson,

We would like to inform you that there have been breaking changes in the 21.1.35 version onwards for the file stream argument for the Change event. We recommend referring to the release notes for more information on these changes. You can find the release notes on the Syncfusion Blazor documentation page here: https://blazor.syncfusion.com/documentation/release-notes/21.1.35?type=all#breaking-changes-7

We suggest using the updated code provided in the release notes to resolve the issue you are facing.

code changes here:


Regards,

Sureshkumar P



AN Anderson May 26, 2023 07:07 PM UTC

Hello,

I created an example project with the suggested code but I get an error... I must be missing something... Could you help me?

Attached is code.


Attachment: SfBlazorUpload_b45ad655.zip


UD UdhayaKumar Duraisamy Syncfusion Team May 30, 2023 12:23 PM UTC

Based on the information, we suspect that you are facing complexity in obtaining the memory stream of the uploaded file. You can obtain the stream of the file as shown in the code snippet below.


@using Syncfusion.Blazor.Inputs

 

<div style="margin:130px auto;width:300px">

    <SfUploader>

        <UploaderEvents ValueChange="@OnChange"></UploaderEvents>

    </SfUploader>

</div>

@code {

    private async Task OnChange(UploadChangeEventArgs args)

    {

        try

        {

            foreach (var file in args.Files)

            {

                MemoryStream memoryStream = new MemoryStream();

                using var fileStream = file.File.OpenReadStream(long.MaxValue);

                await fileStream.CopyToAsync(memoryStream);

 

                //memoryStream will contain the stream of the file and you can use it for your requirement

            }

        }

        catch (Exception ex)

        {

            Console.WriteLine(ex.Message);

        }

    }

}



Marked as answer

AN Anderson replied to UdhayaKumar Duraisamy May 30, 2023 04:59 PM UTC

Exactly that, thank you very much.



UD UdhayaKumar Duraisamy Syncfusion Team May 31, 2023 05:07 AM UTC

We are pleased that the suggestion helped you to meet your needs. Please let us know if you require any further assistance.


Loader.
Up arrow icon