In the earlier article, We saw how to enable Moderation. In the same manner, we need to enable the major and minor versioning in SharePoint Office 365 Lists Programmatically using CSOM C#.
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 = "xxx";
string userName = "xxx";
string password = "xxx";
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.UpdateListVersioning(true, false, true); 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();
}
}
}
The parameters for the UpdateList Versioning is also very straight forward.
Happy Coding,
Sathish Nadarajan.
Leave a comment