How to Create SharePoint Calendar View Programmatically in SharePoint 2013/2010 using CSOM?

Hello SharePointers,

A SharePoint calendar is  simply a type of list — a collection of information that you can share with anyone who has access to the site. This sharepoint list contains calendar entries, its items have specific dates and times associated with them. In this article, we will see how to create a Calendar View Programmatically using Client Side Object Model. Below are the Code snippet given below.

using (var site = new SPSite(“http://mysite”))
var viewFields = new System.Collections.Specialized.StringCollection { dateStartName, dateEndName, titleName };

var query = string.Format(“<FieldRef Name='{0}’ />”, dateStartName, dateEndName);
var viewData = string.Format(“”, titleFieldName);

var list = site.RootWeb.Lists[“MyLeavesystem”];
var ManagerView = list.Views.Add(“Calendar”, viewFields, query, 0, true, false, SPViewCollection.SPViewType.Calendar, false);
ManagerView .ViewData = viewData;
ManagerView .MobileView = true;
ManagerView .Update();


Hope it helps my fellow sharepoint pals!! Happy SharePointing !!!




Leave a Reply

Your email address will not be published. Required fields are marked *