Your search did not match any results.
FileUploader

Validation

This demo shows how to use the allowedFileExtensions and maxFileSize options to limit the maximum size and specify file extensions that the FileUploader accepts. Note that demonstrated validation is client-side — you should implement the server-side validation. You can see an example under the FileUploaderController tab.

<div class="main-block"> <div class="file-uploader-block"> @(Html.DevExtreme().FileUploader() .Name("imageFile") .Accept("*") .Multiple(true) .AllowedFileExtensions(new List<string> { ".jpg", ".jpeg", ".gif", ".png" }) .UploadMode(FileUploadMode.UseButtons) .UploadUrl(Url.Action("UploadImage", "FileUploader")) ) <span class="note">Allowed file extensions: <span>.jpg, .jpeg, .gif, .png</span>.</span> </div> <div class="file-uploader-block" style="float: right"> @(Html.DevExtreme().FileUploader() .Name("smallFile") .Accept("*") .Multiple(true) .MaxFileSize(4000000) .UploadMode(FileUploadMode.UseButtons) .UploadUrl(Url.Action("UploadSmallFile", "FileUploader")) ) <span class="note">Maximum file size: <span>4 MB.</span></span> </div> </div>
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Web; using System.Web.Http.Results; using System.Web.Mvc; namespace DevExtreme.MVC.Demos.Controllers { public class FileUploaderController : Controller { public ActionResult Validation() { return View(); } public ActionResult UploadImage(HttpPostedFileBase imageFile) { try { string[] imageExtensions = { ".jpg", ".jpeg", ".gif", ".png" }; var fileName = imageFile.FileName.ToLower(); var isValidExtenstion = imageExtensions.Any(ext => { return fileName.LastIndexOf(ext) > -1; }); if (isValidExtenstion) { // Uncomment to save the file //var path = Server.MapPath("~/Content/Files/"); //if (!Directory.Exists(path)) // Directory.CreateDirectory(path); //file.SaveAs(path); } } catch { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } return new EmptyResult(); } [HttpPost] public ActionResult UploadSmallFile(HttpPostedFileBase smallFile) { try { var maxFileSize = 4000000; if (smallFile.InputStream.Length < maxFileSize) { // Uncomment to save the file //var path = Server.MapPath("~/Content/Files/"); //if (!Directory.Exists(path)) // Directory.CreateDirectory(path); //file.SaveAs(path); } } catch { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } return new EmptyResult(); } } }
.file-uploader-block { width: 350px; float: left; } .note { font-size: 10pt; color: #484848; margin-left: 9px; } .note > span { font-weight: 700 } .main-block { max-width: 900px; min-width: 700px; }