Skip to main content
All docs
V24.2

IFileInputSelectedFile.CancellationTokenSource Property

Returns the file’s cancellation token source.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

CancellationTokenSource CancellationTokenSource { get; }

Property Value

Type Description
CancellationTokenSource

The file’s cancellation token source.

Remarks

Once the File Input component starts to upload a file, the component generates a cancellation token source for this file. The cancellation token source notifies the FilesUploading event’s handler if the file’s upload operation is canceled.

The File Input component cancels file upload process in response to the following actions:

Cancel Button Click
When an upload operation is in progress, users can click a cancel button to interrupt the active file upload process. Disable the AllowCancel property to hide cancel buttons and prevent users from canceling upload operations.
Cancel Method Call
You can call the CancelAllFilesUpload, CancelFilesUpload, or CancelFileUpload method to cancel upload operations.

The OpenReadStream method throws an exception if the file’s upload operation is canceled during the method execution. The following example handles upload operation cancellations:

<DxFileInput FilesUploading="OnFilesUploading" />

@code{
    async Task OnFilesUploading(FilesUploadingEventArgs args) {
        foreach (var file in args.Files) {
            try {
                /* The following code is intended for demonstration purposes only.
                Do not read a stream directly in memory to avoid performance and security-related issues. */
                using var stream = new System.IO.MemoryStream();
                await file.OpenReadStream(file.Size).CopyToAsync(stream);
            }
            catch (OperationCanceledException ex) {
                // Handle the cancel action here
            }
        }
    }
}
See Also