How to Enable Major, Minor Versioning in SharePoint Office 365 Lists programmatically using CSOM C#


Sathish Nadarajan
SharePoint MVP
Published On :   04 Jan 2017
Visit Count
Today :  1    Total :   1586
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

Sharegate: Kick-Ass Tool
Think Your SharePoint & Office 365 Are Secure ? Find Out Now!


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.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

SharePoint Analytics