Back to Devexpress

DxFileInput.AllowCancel Property

blazor-devexpress-dot-blazor-dot-dxfileinput-8417d0f5.md

latest3.7 KB
Original Source

DxFileInput.AllowCancel Property

Specifies whether users can cancel upload operations.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

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

Property Value

TypeDefaultDescription
Booleantrue

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:

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

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

DxFileInput Class

DxFileInput Members

DevExpress.Blazor Namespace