Skip to main content
All docs
V24.2

DxFileInput.AllowCancel Property

Specifies whether users can cancel upload operations.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[DefaultValue(true)]
[Parameter]
public bool AllowCancel { get; set; }

Property Value

Type Default Description
Boolean true

true to allow users to cancel file upload; otherwise, false.

Remarks

When an upload operation is in progress, users can click a cancel button to interrupt the active file upload process. Set the AllowCancel property to false to hide cancel buttons and prevent users from canceling upload operations.

Note

The AllowCancel property does not affect CancelFileUpload, CancelFilesUpload, and CancelAllFilesUpload methods.

The following example prevent users from canceling upload operations:

File Input Hidden Cancel Button

<DxFileInput FilesUploading="OnFilesUploading" AllowCancel="false" />

@code{
    async Task OnFilesUploading(FilesUploadingEventArgs args) {
        foreach (var file in args.Files) {
            /* 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);
        }
    }
}

Users can reload or remove files whose upload process was canceled. Call the following methods to manage such files in code:

To respond to an upload process cancel action, specify the try..catch statement in the FilesUploading event’s handler as follows:

<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