It is rather a common scenario, where we might have a requirement to upload a file to a SharePoint List as an attachment. SharePoint provides the flexibility to upload multiple attachments to a specific list item, contrary to the library functionality of a single document upload per item. We can add an attachment to the list item out of the box, if the list settings permits the user to do so.

attachment

If enabled, we can attach the multiple attachments to a particular list item.

attachments

Whenever an attachment is added, internally, SharePoint creates an attachment folder for each item it is attached to. If there is no attachment for a list item, it won’t have an attachment folder. The attachment folder for a particular item will be located at the URL given below:

https://SiteURL/sites/Playground/Lists/ListName/Attachments/1

ListName is the name of the list. ‘1’ is the folder name that is created with the name as List item ID.

Let’s see how we can implement uploading of the attachments to the list item, using JavaScript Object Model,

We can test this in SharePoint by adding it to the Content Editor Web part.

Once we browse and click on upload it will upload the attachment file to the specified List Item.

file

Thus, we have seen how we can upload a list item as an attachment to a SharePoint list Item.

Pitfall

However, there is a limitation for this method. JavaScript object model allows only the upload of the files, which are less than or equal to 5 MB in size. Any file above the file limit cannot be uploaded using JSOM. Instead, we will have to use REST to perform the upload, which will be covered in an upcoming article.