How to enable / disable attachments to list items in the SharePoint Site using CSOM

Enable/disable attachments to list items in the SP Site using CSOM


Hi All,

Below example shows how to disable attachments to list items in the SharePoint site using the .Net Client Side Object Model.(CSOM).

Below code helps to achieve goal.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.Security;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ClientContext clientContext = new ClientContext(" <Your SharePoint Site URL>");
            var passWord = new SecureString();
            foreach (char c in "password".ToCharArray()) passWord.AppendChar(c);
            // Authentication-with-sharepoint-online-and-the-client-side-object-model
            clientContext.Credentials = new SharePointOnlineCredentials("Loginname@Yoursite.onmicrosoft.com", passWord);
            // Get the SharePoint list by title
            List olist = clientContext.Web.Lists.GetByTitle("Your Custom list");
            olist.EnableAttachments = false; // Disable attachments to list items
            olist.EnableAttachments = true;  // Enable attachments to list items
            // Update the list
            olist.Update();
            //Execute the query
            clientContext.ExecuteQuery();
        }
    }

}

Happy Coding :-)
पुढे
« Prev Post
Previous
Next Post »