Tuesday, 28 January 2014

Multiple file upload

// Add multiple= true

<asp:FileUpload ID="FileUpload1" multiple="true" runat="server" />

// c# code on upload click
if (FileUpload1.HasFile) // CHECK IF ANY FILE HAS BEEN SELECTED.
{
   int iUploadedCnt = 0;// to count files
   HttpFileCollection hfc = Request.Files;
 
   for (int i = 0; i <= hfc.Count; i++)
   {
      HttpPostedFile hpf = hfc[i];
      if (hpf.ContentLength > 0)
      {
         filename = Path.GetFileName(hpf.FileName);
         hpf.SaveAs(Server.MapPath("~/images/") + Path.GetFileName(hpf.FileName));
         iUploadedCnt += 1;
      

       }
   }
   lblMessage.Text = "<b>" + iUploadedCnt + "</b> file(s) Uploaded.";
}
else
{
  Give msg Here // lblMessage.Text ="No files selected.";
}

No comments:

Post a Comment