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

Sathish Nadarajan
 
Solution Architect
January 4, 2017
 
Rate this article
[Total: 0    Average: 0/5]
 
Views
3447

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.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
[Total: 0    Average: 0/5]
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 13+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment