In this article, let us see how to Enable / Disable Content Approval (Moderation) in SharePoint Lists using CSOM.
Recently I met with a requirement that, whenever a List is being created, a Remote Event Receiver will get triggered. Based on the List Template, we need to do some basic works on the remove event receiver. Out of that, one thing is Enable / disable the Content approval.
The code is straight forward.
namespace Sathish.Demo
{
using Microsoft.SharePoint.Client;
using System;
class Program
{
static void Main(string[] args)
{
EnableModeration();
}
public static void EnableModeration()
{
OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
string siteUrl = "https://*******.sharepoint.com/sites/CommunitySite";
string userName = "Sathish@******.com";
string password = "***************";
using (var clientContext = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
{
try
{
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.Load(web.Lists);
clientContext.ExecuteQuery();
List list = web.Lists.GetByTitle("D10");
list.EnableModeration = false;
list.Update();
clientContext.ExecuteQuery();
}
catch (Exception ex)
{
System.Console.ForegroundColor = ConsoleColor.Red;
System.Console.WriteLine("Exception Occured : " + ex.Message);
System.IO.File.AppendAllText("C:\Temp\Exception.txt", ex.Message + " - " + siteUrl + Environment.NewLine);
}
}
System.Console.WriteLine("Completed....");
System.Console.WriteLine("Press Any Key to Exit ....");
System.Console.ReadLine();
}
}
}
Happy Coding,
Sathish Nadarajan.
Leave a comment