Class UploadFiles
Represents the details of uploaded files in the SfUploader component.
Inheritance
Namespace: Syncfusion.Blazor.Inputs
Assembly: Syncfusion.Blazor.dll
Syntax
public class UploadFiles : Object
Remarks
This class encapsulates comprehensive information about files that have been uploaded through the uploader component. It provides access to both the file metadata and the actual file content, enabling developers to process uploaded files, save them to storage, or perform validation and manipulation operations on the uploaded data.
Constructors
UploadFiles()
Declaration
public UploadFiles()
Properties
File
Gets the browser file data representing the uploaded file from the SfUploader component.
Declaration
public IBrowserFile File { get; }
Property Value
Type | Description |
---|---|
Microsoft.AspNetCore.Components.Forms.IBrowserFile | An Microsoft.AspNetCore.Components.Forms.IBrowserFile object representing the uploaded file, or |
Remarks
The File property is used to handle file uploads in Blazor applications.
It represents the file selected by the user in the browser and provides access to the file's metadata,
such as the file name, size, and content type. To read the contents of the uploaded file,
call the OpenReadStream()
method of the Microsoft.AspNetCore.Components.Forms.IBrowserFile interface, which returns a stream that you can use
to read the file data. This is the recommended approach for accessing file content in modern implementations.
Examples
The following example demonstrates how to handle file uploads and save them to disk:
<SfUploader AutoUpload="true">
<UploaderEvents ValueChange="@OnChange"></UploaderEvents>
</SfUploader>
@code{
private async Task OnChange(UploadChangeEventArgs args)
{
try
{
foreach (var file in args.Files)
{
var path = @"D:\" + file.FileInfo.Name;
FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);
await file.File.OpenReadStream(long.MaxValue).CopyToAsync(filestream);
filestream.Close();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
FileInfo
Gets the detailed information about the selected file.
Declaration
public FileInfo FileInfo { get; }
Property Value
Type | Description |
---|---|
FileInfo | A FileInfo object containing comprehensive file details, or |
Remarks
This property provides access to comprehensive metadata about the uploaded file, including name, size, type, upload status, and other properties. This information is essential for file validation, processing decisions, and user interface updates.
Stream
Gets the memory stream containing the selected file data.
Declaration
public MemoryStream Stream { get; }
Property Value
Type | Description |
---|---|
System.IO.MemoryStream | A System.IO.MemoryStream containing the file data, or |
Remarks
This property provides access to the file content as a memory stream. Note: This property
is obsolete and will be removed in a future version. Use the File property instead to access
the uploaded file's stream through the OpenReadStream()
method.