taha suliman

taha suliman

  • 1.3k
  • 364
  • 5.8k

Can not Upload All files using Dropzone Multifiles upload ,MVC C#,

Jun 29 2020 9:39 AM
I added a drop-down library to my project when I picked a bunch of files.

And press the file upload button. The code only uploads one file and ignores the rest of the files.

It does not save the name and extension of files in the database. I don’t know where the error is ??

Note: All files are successfully uploaded if the save code is cleared
  1. public ActionResult Upload()  
  2. {  
  3.     FILES_TABLE ft = new FILES_TABLE();  
  4.   
  5.     bool isSavedSuccessfully = true;  
  6.     string fName = "";  
  7.     try  
  8.     {  
  9.         foreach (string fileName in Request.Files)  
  10.         {  
  11.             HttpPostedFileBase file = Request.Files[fileName];  
  12.             fName = file.FileName;  
  13.             if (file != null && file.ContentLength > 0)  
  14.             {  
  15.                 var path = Path.Combine(Server.MapPath("~/MyImages"));  
  16.                 string pathString = System.IO.Path.Combine(path.ToString());  
  17.                 string fileName1 = Path.GetFileName(file.FileName);  
  18.                 string ext1 = System.IO.Path.GetExtension(file.FileName);  
  19.                 bool isExists = System.IO.Directory.Exists(pathString);  
  20.                 if (!isExists) System.IO.Directory.CreateDirectory(pathString);  
  21.                 var uploadpath = string.Format("{0}\\{1}", pathString, file.FileName);  
  22.                 file.SaveAs(uploadpath);  
  23.   
  24.                 ft.FileName = fileName1;  
  25.                 ft.FileExt = ext1;  
  26.                 _DB.FILES_TABLE.Add(ft);  
  27.                 _DB.SaveChanges();  
  28.             }  
  29.         }  
  30.     }  
  31.     catch (Exception ex)  
  32.     {  
  33.         isSavedSuccessfully = false;  
  34.         ViewBag.Err = "{0} Exception caught." + ex;  
  35.     }  
  36.     if (isSavedSuccessfully)  
  37.     {  
  38.         return RedirectToAction("Index");  
  39.     }  
  40.     else  
  41.     {  
  42.         return Json(new  
  43.         {  
  44.             Message = "Error in saving file"  
  45.         });  
  46.     }  
  47.   

Answers (1)