How to enable or disable attachments in SharePoint Online + PowerShell

In this SharePoint tutorial, we will discuss how to enable or disable attachments in SharePoint Online.

We can also use the SharePoint server object model to disable or enable attachments in SharePoint server 2019.

We will also check how to disable attachment SharePoint list programmatically using csom.

Disable or enable attachments in SharePoint Online

Now, we will see how to disable or enable attachments in list in SharePoint Online.

By default, the SharePoint list will have the attachment field enabled. But sometimes, we may need to disable the attachment field in the SharePoint list.

You can see the attachment field will appear below in the SharePoint Online list or SharePoint Server 2019 modern list.

disable attachments in SharePoint Online
disable attachments in SharePoint Online

We can easily disable attachments in SharePoint list from the list settings page in the browser itself.

Open the SharePoint Online List -> List settings -> Advance Settings -> Disable Attachment like below:

disable attachments sharepoint list
disable attachments sharepoint list

Disable attachments in SharePoint Online using PowerShell

Now, we will see how to disable attachments in SharePoint Online using PowerShell.

Write the below PowerShell script.

disable attachments sharepoint list
disable attachments sharepoint list powershell
$Username="[email protected]" 
$AdminPassword="Pass" 
$Url="https://pikasha12.sharepoint.com/sites/Blogs/" 
$ListName="Disable Attachment" 
$Attachments =$false

Disable attachments in SharePoint Server 2019

We can also disable attachments in the SharePoint server 2019 using the server object model code.

You can make the EnableAttachments property to false like below:

using (SPSite site = new SPSite("http://SiteURL"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["MyCustomList"];
list.EnableAttachments = false
list.update();
}
}

Once you run the above code the attachment field will be disabled for the particular list. You can see fig below:

disable or enable attachments in SharePoint Online

Disable SharePoint List item attachment using CSOM

Now, we will see how to disable the attachment field in the SharePoint list item programmatically using CSOM.

You can run the code using a windows application or console application using Visual Studio for SharePoint.

ClientContext clientContext = new ClientContext("https://Site URL");  
Web web = clientContext.Web;
List list = web.Lists.GetByTitle("Your List Name");
list.EnableAttachments = false;
list.Update();
clientContext.ExecuteQuery();

You may like the following SharePoint tutorials:

In this SharePoint tutorial, we learned how to enable or disable attachments in SharePoint Online or SharePoint 2019 or SharePoint 2016/2013.

We saw how to disable attachments in SharePoint list using SharePoint server object model and using PowerShell and using client side object model (CSOM).

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>