Here I will explain how to use the SharePoint 2013 calendar color overlay, to give a different color for each category.  Calendar color overlay in SharePoint is by stacking several views that have been created with the filter each category, but it also set up an empty view for displaying data named Calendar Canvas as the foundation to be coated view-view is already filtered by category.

Items in the calendar will be color coded based on their assigned category. This example is using ten category choices in the Category column of a Calendar list: category 1, category 2, category3, category4, category5, category 6, category7, category7, category8, category9, category10. Ten public list views will be created, with each view set to filter and display one of the ten category choices. Finally the views will have all associating overlay calendar views (New Calendars) created to enabled color coding.

  • Create an empty SharePoint project
  • Add some housekeeping folders.
  • Add some Modules to get our content into SharePoint
  • Create a new Content Type called RollUpCalendarContentType.  With associated artifacts.
  • Create the Calendar Web Part
  • Create some Artifacts need to make the calendar work
  • Complete the solution add a master with JQuery and a Page layout.
  • Create Empty SharePoint 2010 Project
  • Add new folder called Modules and add two Modules to this folder called CSS and Scripts.
  • image Add JQuery to the scripts module and rename Sample.txt to calScripts.js
  • Create a Folder called Code and add these classes to the folder changing names spaces to reflect this project.  I know some would say create a DLL and reference that in your project but I have had occasion to use a 3rd party solution where the DLL was not available so I choose to keep my dependencies self contained as much as possible. image
  • We need to create a Content Type that inherits from Event so lets create an Event Receiver and Create one.  When we added our Modules Visual Studio in its Goodness automatically added a Feature called feature1 let’s rename it to AddCalendarArtifacts this will be a feature that is site scoped so we can add the Scripts, CSS, Site Columns and Content Type within this feature.  The Scripts and CSS Modules are already added to this feature so we need to add an Event Receiver here to add our content type.
  • The difference between this content type and Event is that I will be adding a look up field which will lookup a a category from a List called  CalendarCategories  from  the Title column and a new column called MilCategory.   Therefore I need to create a list instance called “CalendarCategories”.  Since this list will only be instantiated at the Site Collection level we can add this list instance in this event receiver.  Here is the Event Receiver:
    using System;
    using System.Runtime.InteropServices;
    using System.Security.Permissions;
    using Microsoft.SharePoint;
    using Demo.Calendar.Code;
    using System.Collections;
    namespace Demo.Calendar.Features.AddCalendarArtifacts
    {
    [Guid(“4c1beeb2-9bb5-488f-8220-53e2627b6ebe”)] public class AddCalendarArtifactsEventReceiver : SPFeatureReceiver
    {
    const string columnGroup = “Demo”;
    const string ctName = “RollUpCalendarContentType”;
    // Uncomment the method below to handle the event raised after a feature has been activated.
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
    using (SPWeb spWeb = properties.GetWeb() as SPWeb)
    {
    if ((spWeb.Lists.TryGetList(“CalendarCategories”) == null))
    {
    //create the list if it doesn’t   exist
    CreateCalendarCategoryList(spWeb);
    }
    //add the fields
    addFields(spWeb);
    //add content type
    SPContentType testCT = spWeb.ContentTypes[ctName];
    // we will not create the content type if it exists
    if (testCT == null)
    {
    //the content type does not exist add it
    addContentType(spWeb, ctName);
    }
    }
    }
    public void addFields(SPWeb spWeb)
    {
    Utilities.addLookupField(spWeb, “CalendarCategories”, “Title”, “MilCategory”, columnGroup);
    }

    private static void addContentType(SPWeb spWeb, string name)
    {
    SPContentType myContentType = new SPContentType(spWeb.ContentTypes[“Event”], spWeb.ContentTypes, name) { Group = columnGroup };

    spWeb.ContentTypes.Add(myContentType);
    addContentTypeLinkages(spWeb, myContentType);
    myContentType.Fields.Delete(“Category”);
    myContentType.Update();
    }

    public static void addContentTypeLinkages(SPWeb spWeb, SPContentType ct)
    {
    Utilities.addContentTypeLink(spWeb, “MilCategory”, ct);
    }
    private void CreateCalendarCategoryList(SPWeb web)
    {
    Guid newListGuid = web.Lists.Add(“CalendarCategories”, “Calendar Categories.”,
    SPListTemplateType.GenericList);
    SPList newList = web.Lists[newListGuid];
    ArrayList choices = new ArrayList() { “Training”, “Deploymment”, “Deployed” };
    foreach (string iTem in choices)
    {
    SPListItem itemToAdd = newList.Items.Add();
    itemToAdd[“Title”] =iTem;
    itemToAdd.Update();
    }
    newList.Update();
    }
    }
    }

  • In addition we will need to create the Calendar List which can be Instantiated within any web in our site collection called RollupCalendar.  Thus we need a feature scoped to Web with an Event Receiver to create the List.

    the code for this event receiver is:
    using System;
    using System.Runtime.InteropServices;
    using System.Security.Permissions;
    using Microsoft.SharePoint;
    using Demo.Calendar.Code;
    namespace Demo.Calendar.Features.AddCalendarList
    {
    [Guid(“8fa5c174-1c5a-4506-9204-7ffaf3a73dcc”)] public class AddCalendarListEventReceiver : SPFeatureReceiver
    {
    const string columnGroup = “Demo”;
    const string ctName = “RollUpCalendarContentType”;
    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
    using (SPWeb spWeb = properties.GetWeb() as SPWeb)
    {
    if ((spWeb.Lists.TryGetList(“RollupCalendar”) == null))
    {
    //create the list if it dosen’t to exist
    CreatecalendarList(spWeb);
    }
    }
    }
    private void CreatecalendarList(SPWeb web)
    {
    Guid newListGuid = web.Lists.Add(“RollupCalendar”, “Custom Calendar.”,
    SPListTemplateType.Events);
    SPList newList = web.Lists[newListGuid];
    newList.ContentTypesEnabled = true;
    var cal = web.Site.RootWeb.ContentTypes[ctName];
    newList.ContentTypes.Add(cal);
    newList.ContentTypes.Delete(newList.ContentTypes[“Event”].Id);
    newList.Update();
    var view = newList.DefaultView;
    //add all view fields here
    SPContentType ct = cal as SPContentType;
    SPField field = ct.Fields.GetField(“MilCategory”);
    view.ViewFields.Add(field);
    view.Update();
    }

    }
    }

  • Here is our  Rollup Calendar List:
  • Go to Settings and activate the site feature: