Upload multile files dynamically using MVC4
could you please tell me how to upload multiple documents and store in database dynamically using mvc4
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Oct 28, 2013, 11:27 PM EDT
You can use file input element as shown below,
View:
Controller:
[HttpPost]
public ActionResult Upload()
{
var file = Request.Files[0];
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Images/"), fileName);
file.SaveAs(path);
}
return RedirectToAction("UploadDocument");
}
More details on uploading files, read articles,
- Uploading Multiple Files in ASP.NET 2.0: Part II
pload dynamicallyanil babu99 reputationPosted Jan 29, 2014, 3:38 AM EST
Select must 10 images***
CS Code:
public ActionResult Create(HttpPostedFileBase[] MultipleFiles, FormCollection collection, demoproduct p) { try { // TODO: Add insert logic here var Tagid = collection["TagNo"]; var qry = (from c in db.demoproducts where c.TagNo == Tagid select c).Count(); if (qry != 1) { foreach (var fileBase in MultipleFiles) { if (fileBase.ContentLength > 0) { Microsoft.WindowsAzure.StorageClient.CloudBlobContainer blobContainer = _myBlobStorageService.GetCloudBlobContainer(); CloudBlob blob = blobContainer.GetBlobReference(fileBase.FileName); blob.UploadFromStream(fileBase.InputStream); } } //Retrive Images from blob List blobs = new List(); foreach (var fileBase in MultipleFiles) { Microsoft.WindowsAzure.StorageClient.CloudBlobContainer blobContainer1 = _myBlobStorageService.GetCloudBlobContainer(); CloudBlob blob1 = blobContainer1.GetBlobReference(fileBase.FileName); blobs.Add(blob1.Uri.ToString()); } p.ProductImage = blobs.ElementAt(0).ToString(); p.ProductImage1 = blobs.ElementAt(1).ToString(); p.ProductImage2 = blobs.ElementAt(2).ToString(); p.ProductImage3 = blobs.ElementAt(3).ToString(); p.ProductImage4 = blobs.ElementAt(4).ToString(); p.ProductImage5 = blobs.ElementAt(5).ToString(); db.demoproducts.InsertOnSubmit(p); db.SubmitChanges(); return RedirectToAction("Index"); } else { return RedirectToAction("EventCreationError"); } }catch { //return View(); return RedirectToAction("Create"); } }This is working fine for aploading AND save to database That image urls to database,
Supose i want to i want to select 2mages only at the time of saving that image url's to database not working