DxUpload.AllowCancel Property
Specifies whether users can cancel file upload.
Namespace: DevExpress.Blazor
Assembly:
DevExpress.Blazor.v21.1.dll
NuGet Package:
DevExpress.Blazor
Declaration
[Parameter]
public bool AllowCancel { get; set; }
Property Value
Type |
Description |
Boolean |
true to allow users to cancel file upload; otherwise, false.
|
When file upload is in the progress, users can click the cancel button to interrupt file upload. Handle the FileUploadAborted event to respond to this action. If multiple files are uploaded at once, users can click the common cancel button to cancel upload of all the files.
Users can then reload the file whose upload was canceled. This action raises the FileReloaded event.
Set the AllowCancel property to false to hide the cancel button during the upload process.
<DxUpload Name="myFile" UploadUrl="https://localhost:10000/api/Upload/UploadFile/"
AllowCancel="false">
</DxUpload>
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
[Route("api/[controller]")]
public class UploadController : ControllerBase {
private readonly IWebHostEnvironment _hostingEnvironment;
public UploadController(IWebHostEnvironment hostingEnvironment) {
_hostingEnvironment = hostingEnvironment;
}
[HttpPost]
[Route("UploadFile")]
// "myFile" is the value of the Upload's "Name" property.
public ActionResult UploadFile(IFormFile myFile) {
try {
// Specify the target location for the uploaded files.
var path = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
// Check whether the target directory exists; otherwise, create it.
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
using (var fileStream = System.IO.File.Create(Path.Combine(path, myFile.FileName))) {
// Check the file here (its extension, safity, and so on).
// If all checks are passed, save the file.
myFile.CopyTo(fileStream);
}
} catch {
Response.StatusCode = 400;
}
return new EmptyResult();
}
}
See Also