Showing posts with label Upload Multiple Files. Show all posts
Showing posts with label Upload Multiple Files. Show all posts

Thursday, December 28, 2017

Upload Multiple Files Using FileUpload Control In ASP.NET 4.5 +

ASP.NET 4.5 and upper versions support this feature.

Now, FileUpload  control is built to support HTML 5, therefore it is only supported in browsers supporting HTML5. For other browsers it will work like a normal file upload control in ASP.NET.

A new Attribute introduces with the ASP.NET 4.5 FileUplaod control i.e. AllowMultipleIt takes either true or false.

In order to support multiple file uploads, set AllowMulitple="true" other than false.

<asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />

In addition to this control, some new properties have been included to support code-behind coding.


HasFilesCheck whether FileUpload control has multiple files or not.

PostedFilesBasically used to get all the files from the FileUpload control in the iteration.

Example code to upload files:

   <asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />  
   <asp:Button runat="server" ID="uploadedFile" Text="Upload" OnClick="uploadFile_Click" />  

protected void uploadFile_Click(object sender, EventArgs e) {  
    if (UploadImages.HasFiles) {  
        foreach(HttpPostedFile uploadedFile in UploadImages.PostedFiles) {  
            //code to save files  
        }  
    }  
}