Multiple Files Upload Control in SharePoint

Multiple Files Upload Control in SharePoint
8 votes, 4.75 avg. rating (94% score)


Looking for multiple file upload control in SharePoint 2010 or in SharePoint 2013. This article will provide you code snippet, webpart to download and full source code project

Skill Level – Medium


Aspx page code
Refers jquery library file and opensource Multifile.js for displaying uploaded files in bettter UI

<script type="text/javascript" src="/_layouts/MultifileUpload/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/_layouts/MultifileUpload/jquery.MultiFile.js"></script>
<h3>Upload Attachments</h3>


User interface will be converted after adding js files



Upload file code to insert multiple items into custom list

<summary> /// Code to upload attachments into list 'TestAttachments'
 /// </summary>
        protected void btnUpload_click(object sender, EventArgs e)
                SPWeb webObj = SPContext.Current.Web;
                //change the list name here
                SPList lstObj = webObj.Lists.TryGetList("TestAttachments");
                if (lstObj != null)
                    SPListItem thisItem = lstObj.AddItem();

                    thisItem["Title"] = "This is test by Adi"; //this is only for testing

                    if (Request.Files.Count > 0)
                        SPAttachmentCollection attach = thisItem.Attachments;
                        HttpFileCollection uploadedFiles = Request.Files;
                        Stream attachmentStream;
                        Byte[] attachmentContent;
                        for (int i = 0; i < uploadedFiles.Count; i++)
                            HttpPostedFile userPostedFile = uploadedFiles[i];
                            String fileName = userPostedFile.FileName;
                            attachmentStream = userPostedFile.InputStream;
                            attachmentContent = new Byte[attachmentStream.Length];
                            attachmentStream.Read(attachmentContent, 0, (int)attachmentStream.Length);


                            // Add the file to the attachment collection
                            attach.Add(fileName, attachmentContent);


            catch (Exception ex)
                Response.Write(ex.Message); // put your custom error handling here


When we hit upload, the uploaded files will be saved to ShaerPoint custom list. Here I have used my custom list ‘TestAttachments’.



Download Source Code


Uploading single file is a bit easy but provisioning facility to upload multiple files is a bit tricky. Hope the codes saves your time rather than exploring how to achieve the requirement. Happy coding.

October 9, 2014 В· Adi В· 4 Comments
Tags: ,  В· Posted in: Sharepoint 2010, SharePoint 2013, Tools

4 Responses

  1. vishal wattamwar - January 8, 2016


    This code is working perfectly.
    But when we refresh the page before upload button clicks,it losses the attached file.

    Please do the needful.

  2. Adi - January 29, 2016

    Yes, the file upload control is client side management and does not manage state. You can tweak it by using hidden controls to save the uploaded control file list. In the page refresh try to fill the controls again with hidden control data.


  3. Alex - May 4, 2016

    Hey, there Adi, thanks for posting this. Could you please test this out with files larger than 100 KiB or 1 MiB? Im getting errors when file size is larger than 80 Kilobytes, id like to know if you have same issues here? Thank you!

  4. Adi - May 4, 2016

    Hi Alex,
    There is no limit on the size, it perfectly worked with more than 500MB data file also. May be there is limit set on IIS or any other setting from your end.


Leave a Reply

What is 8 + 7 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)