Back to Devexpress

IFileInputSelectedFile.CancellationTokenSource Property

blazor-devexpress-dot-blazor-dot-ifileinputselectedfile-2ec33943.md

latest2.9 KB
Original Source

IFileInputSelectedFile.CancellationTokenSource Property

Returns the file’s cancellation token source.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
CancellationTokenSource CancellationTokenSource { get; }

Property Value

TypeDescription
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 ClickWhen 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 CallYou 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:

razor
<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

IFileInputSelectedFile Interface

IFileInputSelectedFile Members

DevExpress.Blazor Namespace