title: upload all images contained in folder to database ASP MVC 4 Razor
body: <p>By now I'm able to upload image by image and save it in Database , But since I've several images,  I need to upload all the images contained in a folder one shot.
  Here is my current controller :</p>
  
  <pre><code> [HttpPost]
      public ActionResult Form(HttpPostedFileBase file, DateTime dateParution, long IdJournal, string numEditionJournal)
      {
          var db = new Bd_scanitEntities();
          IEnumerable&lt;SelectListItem&gt; items = db.JournalSet
            .Select(c =&gt; new SelectListItem
            {
                Value = c.Id.ToString(),
                Text = c.label
            }).OrderBy(c =&gt; c.Text);/*_*/
          ViewBag.IdJournal = items;
  
          ScanITAPP.Service.ImageRender service = new Service.ImageRender();
          service.UploadImageToDB(file, dateParution, IdJournal, numEditionJournal);
  
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>And class ImageRender</p>
  
  <pre><code>public void UploadImageToDB(HttpPostedFileBase file, DateTime dateParution, long IdJournal, string numEditionJournal)
      {
  
  
          AnnonceVImgSet annImg = new AnnonceVImgSet();
          annImg.Id = 1;
  
          ImgOrgSet img = new ImgOrgSet();
  
          img.User_Id = 1;
          img.Journal_Id = IdJournal;
          img.dateModif = DateTime.Now;
          img.dateParution = dateParution;
          img.dateSaisi = DateTime.Now;
          img.numEditionJournal = numEditionJournal;
  
          img.image = ConvertToBytes(file);
          using (Bd_scanitEntities dbContext = new Bd_scanitEntities())
          {
              dbContext.ImgOrgSet.Add(img);
              dbContext.SaveChanges();
          }
  
      }
  
      public byte[] ConvertToBytes(HttpPostedFileBase Image)
      {
          byte[] image = null;
          BinaryReader reader = new BinaryReader(Image.InputStream);
          image = reader.ReadBytes((int)Image.ContentLength);
          return image;
      }
  </code></pre>
  
  <p>And the view:</p>
  
  <pre><code> @using (Html.BeginForm("Form", "Home", FormMethod.Post, new { @enctype = "multipart/form-data" }))
                 {     
  &lt;div class="modal-dialog"&gt;
             &lt;div class="modal-content"&gt;
                  &lt;div class="modal-header"&gt;
                       &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                       &lt;h4 id="myModalAlertLabel" class="modal-title"&gt;Import&lt;/h4&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-body"&gt;
  
                          &lt;table cellpadding="2" cellspacing="10"&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;
                                      Choisir journal :
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      @Html.DropDownList("IdJournal")
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;
                                      Numéro de l'édition:
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;input type="text" name="numEditionJournal" /&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;
                                      Date de parution:
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;input class="form-control span2" name="dateParution" size="16" type="date" value="12-02-2014" &gt;
  
  
                              &lt;/tr&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;
                                      Choisirr image:
                                  &lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;input type="file" name="file" id="upload"/&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/table&gt;
  
  
                  &lt;/div&gt;
                  &lt;div class="modal-footer"&gt;
  
                       &lt;button type="submit" id="load" class="btn btn-primary"&gt;Confirmer&lt;/button&gt;
                  &lt;/div&gt;
            &lt;/div&gt;
      &lt;/div&gt;
                 }
  </code></pre>