Anyway, I've been using Dropzone.js for drag and drop file uploads.
If you are using ASP.NET MVC then just make reference to the relevant dropzone css/js.
Add drop zone to the page for example
Code:
<div id="dropzone"> <form action="@Url.Action("Upload", "ControllerNameHere")" class="dropzone dz-clickable" id="demoUpload" style="border: 2px dashed #816bb1"> @Html.EditorFor(model => model.TemporaryId) <div class="dz-message"> Drop files here or click to upload.<br /> </div> </form> </div>
Code:
[HttpPost] public ActionResult Upload(string temporaryId) { try { //use the temp id to create a folder structure for the uploaded images. foreach (string fileName in Request.Files) { var file = Request.Files[fileName]; //Save file content goes here //name = file.FileName; if (file != null && file.ContentLength > 0) { var originalDirectory = new DirectoryInfo(string.Format("{0}\\temp\\upload", Server.MapPath("~"))); var pathString = Path.Combine(originalDirectory.ToString(), temporaryId); if (!Directory.Exists(pathString)) Directory.CreateDirectory(pathString); var path = string.Format("{0}\\{1}", pathString, file.FileName); file.SaveAs(path); } } } catch (Exception exception) { log.Error("Error uploading files " + exception); return Json(new { success = "False" }); } return Json(new { success = "True" }); }
Leave a comment: