Your search did not match any results.
File Uploader

File Uploading

In this demo, the FileUploader widget is configured for asynchronous upload. Use the File types drop-down menu to select acceptable file types for the Open file dialog. The Upload mode drop-down menu allows you to specify whether the file is uploaded on a button click or instantly after the file has been selected. In addition, you can specify whether the widget allows multiple file selection.

To select files, click the Select file button or drop the files directly on the widget. If the upload mode is "useButtons", you must click the Upload button or a corresponding button for each file to initiate upload.

IMPORTANT: This demo does not actually upload files. To upload files, assign the URL of a page providing server scenarios for saving uploaded files to the uploadUrl configuration option of the widget.
<div id="fileuploader"> <div id="file-uploader"></div> @(Html.DevExtreme().FileUploader() .ID("file-uploader") .Name("myFile") .Multiple(false) .Accept("*") .UploadMode(FileUploadMode.Instantly) .UploadUrl(Url.Action("Upload", "FileUploader")) .OnValueChanged("fileUploader_valueChanged") ) <div class="content"> <h4>Options</h4> <div> <div>File types:</div> @(Html.DevExtreme().SelectBox() .DataSource(new object[] { new { name = "All types", value = "*" }, new { name = "Images", value = "image/*" }, new { name = "Videos", value = "video/*" } }) .ValueExpr("value") .DisplayExpr("name") .Value("*") .Width(200) .OnValueChanged("acceptOption_changed") .ElementAttr(new Dictionary<string, object> { { "class", "option" } }) ) </div> <div> <div>Upload mode:</div> @(Html.DevExtreme().SelectBox() .DataSource(new string[] { "instantly", "useButtons" }) .Value("instantly") .Width(200) .OnValueChanged("uploadMode_changed") .ElementAttr(new Dictionary<string, object> { { "class", "option" } }) ) </div> @(Html.DevExtreme().CheckBox() .Value(false) .Text("Allow multiple files selection") .OnValueChanged("multipleOption_changed") ) </div> <div class="content" id="selected-files"> <div> <h4>Selected Files</h4> </div> </div> </div> <script> function getFileUploaderInstance() { return $("#file-uploader").dxFileUploader("instance"); } function fileUploader_valueChanged(e) { var files = e.value; if(files.length > 0) { $("#selected-files .selected-item").remove(); $.each(files, function(i, file) { var $selectedItem = $("<div />").addClass("selected-item"); $selectedItem.append( $("<span />").html("Name: " + + "<br/>"), $("<span />").html("Size " + file.size + " bytes" + "<br/>"), $("<span />").html("Type " + file.type + "<br/>"), $("<span />").html("Last Modified Date: " + file.lastModifiedDate) ); $selectedItem.appendTo($("#selected-files")); }); $("#selected-files").show(); } else $("#selected-files").hide(); } function acceptOption_changed(e) { getFileUploaderInstance().option("accept", e.value); } function uploadMode_changed(e) { getFileUploaderInstance().option("uploadMode", e.value); } function multipleOption_changed(e) { getFileUploaderInstance().option("multiple", e.value); } </script>
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; namespace DevExtreme.MVC.Demos.Controllers { public class FileUploaderController : Controller { public ActionResult FileUploading() { return View(); } [HttpPost] public ActionResult Upload() { // Learn to use the entire functionality of the dxFileUploader widget. // var myFile = Request.Files["myFile"]; var targetLocation = Server.MapPath("~/Content/Files/"); try { var path = Path.Combine(targetLocation, myFile.FileName); //Uncomment to save the file //myFile.SaveAs(path); } catch { Response.StatusCode = 400; } return new EmptyResult(); } } }
#selected-files { display: none; } .content h4 { margin-bottom: 10px; font-weight: 500; font-size: 18px; } .option{ margin-bottom: 10px; } .content { margin-top: 50px; margin-left: 10px; } .selected-item { margin-bottom: 20px; }