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)
{
}
}
}
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
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.
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); } } } |
Exactly that, thank you very much.
We are pleased that the suggestion helped you to meet your needs. Please let us know if you require any further assistance.