I am looking for a solution to upload multiple files (click on browse button, and select multiple files using shift key).
I see several solutions that need to be upl
We have been using the below jQuery plugin to help us.
jQuery Multiple File Upload Plugin
After including the necessary js
file : jQuery.multifile.pack.js
, we can use it like below.
Giving class="multi"
makes it to accept more than one file.
You can also apply the constraints if you want. Like class = "max-3"
would allow maximum three files to be uploaded. class = "accept-gif|jpg"
would only allow files with gif
OR jpg
extensions to be uploaded.
For getting the multiple files on the sever side you will need to include the namespace
: System.Web;
Then you can have the below code for iterating through each file uploaded.
if (Request.Files.Count > 0)
{
HttpFileCollection attachments = Request.Files;
for (int i = 0; i < attachments.Count; i++)
{
HttpPostedFile attachment = attachments[i];
if (attachment.ContentLength > 0 && !String.IsNullOrEmpty(attachment.FileName))
{
//do your file saving or any related tasks here.
}
}
}
This would be regardless of .net framework
version.