How To Make Attachments Mandatory In SharePoint Lists

We might come across scenarios where we must work with “attachments”. Ideally, SharePoint libraries are the answer, but due to various reasons, we might still have to use lists rather than a library. Now, there is no direct means to make an “Attachments” field mandatory in SharePoint Lists. But, we can very easily work around this with a some tweaks here and there. Read on to know how!

How To Make Attachments Mandatory In SharePoint Lists 

This article explains how file attachments can be made mandatory in Lists. It can be done in two different ways.

  • CSOM method of making list attachments mandatory
  • InfoPath way of making list attachments mandatory

We will show these methods in a simple list in SharePoint 2010 – Employees, that contains 4 columns.

How To Make Attachments Mandatory In SharePoint Lists 

CSOM method of making list attachments mandatory

This method makes use of the PreSaveAction() method of SharePoint. This method allows us to override the behavior of a “Save” button.

Step 1

Open the list. Right-click “Add new item” and open the page in a new tab. Our goal is to edit the newform.aspx page.
 
How To Make Attachments Mandatory In SharePoint Lists 

Step 2

Edit the page and add a content editor webpart.
 
How To Make Attachments Mandatory In SharePoint Lists 

Step 3

Edit the content editor and add the below code,

  1. function PreSaveAction() {  
  2.     var myAttachments = document.getElementById("idAttachmentsTable");  
  3.     if (myAttachments == null || myAttachments.rows.length == 0) {  
  4.         document.getElementById("idAttachmentsRow").style.display = 'none';  
  5.         alert("Attachments are mandatory for this list. Please attach the appropriate files");  
  6.         return false;  
  7.     } else {  
  8.         return true  
  9.     }  
  10. }  

This concludes the steps. Now users will not be allowed to save the list item without attaching a document.

How To Make Attachments Mandatory In SharePoint Lists 

InfoPath way of making list attachments mandatory

The outline of this method is basically creating a hidden text box that holds the name of the attachment file. Then by creating a validation rule we make sure that the attachment isn’t empty.

Step 1

Open the list for editing in InfoPath,
 
How To Make Attachments Mandatory In SharePoint Lists 

Step 2

Add a new text box. Open its Text Box Properties.
 
How To Make Attachments Mandatory In SharePoint Lists 

Step 3

Set its default value to the Attachment. Click on the “fx”
How To Make Attachments Mandatory In SharePoint Lists 

Step 4

Click on “Insert Field or Group”. Then select the “Attachment”. Follow this link

Insert Field or Group - Attachments - Ok - Ok

How To Make Attachments Mandatory In SharePoint Lists 

Step 5

Create a validation rule in the text box as shown below. In conditions, select the “Attachments” with condition is “not blank”
 
How To Make Attachments Mandatory In SharePoint Lists 

Step 6

Similarly, create a new rule for hiding the text box. This concludes the steps.
 
How To Make Attachments Mandatory In SharePoint Lists 

This article can also be found in my personal blogsite – SharePoint Surgeon