Omicron Llama

Coding all day, every day.

Year-To-View with Sharepoint Calendar

Today I came up with a relatively simple way to produce a (slightly specialised) year-to-view calendar web part for use with Sharepoint Calendar lists.

The Requirement
Our events guys (both of them) use a Sharepoint Calendar to store Events at which our company both hosts and exhibits. This is useful for storing rough details and creating Meeting Workspaces from the event objects in the Calendar.
For strategic planning, the Events manager also uses an Excel Spreadsheet which displays the entire year’s planned events. The columns represent the months and the rows represent the events. Each event row has the date of that particular event in the corresponding month’s column.
See this example:
Event Title Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Event 1 22nd
Event 2 18th
Event 3 14th
Event 4 24th
Event 5 25th
Event 6 2nd
Event 7 20th
Event 8 29th
Event 9 15th
Event 10 2nd

In the table above, Event 1 takes place on March 22nd, Event 2 takes place January 18th, etc. The events need not be listed in Chronological order, as they are often booked many months in advance. We can see that March is a busy month, as there are 2 events in close succession.

This view is, as mentioned, produced in an Excel spreadsheet in such a way that it can be printed. This displays an at-a-glance overview of the events that are on throughout the year, and provides immediate insight into how busy (or not) the department is.
The problem is that the Events guys add events to their Sharepoint Calendar but this requires the manager to manually update her Spreadsheet to reflect changes. Yep, referential integrity issues.
What we would like (that’s their words) is a view on Sharepoint identical (in presentation) to the Excel spreadsheet – but automatically populated and kept itself in sync with the Sharepoint Calendar (which would be updated by the Events guys and their support team via Outlook).
The Solution
My idea is to use a web part to create a DataTable and populate it with items from the user-selected Calendar List.
The Structure
YearToViewWebPart of type WebPart
Properties:
CalendarName – The Display Name (important, this is “Title”, not the “Internal Name”) of the Calendar we wish to generate a table for.
Year – We will only show events in this given year and generate the table as such.
Pseudocode
At time of writing, I have not yet started to write any C# for this at all. I came up with the idea at Finishing Time minus 20 minutes, so I wasn’t going to get my hands dirty 😛 Due to my contract at work I cannot release any code or binaries I create during work time, owing to Intellectual Property clauses. However, I can provide the following pseudocode for anyone to implement in any way they wish.
  • Instantiate a DataTable object
  • Give it 13 columns (1 for event title, 12 for the months)
  • Name the columns appropriately
  • Capture Display Name of Calendar List the user selected. If blank, use “Calendar” as default.
  • Capture the Year the user entered. If blank, use current year as default.
  • Iterate through the ItemList of the Calendar List
  • For Each Item in the List:
  • Extra Year as integer (YYYY) from “Start Date”
  • If Year does not match user-selected year, continue (skip item)
  • Create a DataRow object
  • DataRow[0] = Title of Event
  • DataRow[Month Number] = Day of Month extracted from Start Date
  • If the date is a range, post the range. If the event only occurs on a single day, just post the day.
  • Repeat for all rows
  • Bind DataTable to a DataGrid
  • Apply any formatting as needed by attaching an Event Handler to GridViewRowBound
  • Add to Form
This should display a table like above. The necessary error checking, etc. will need to be added obviously, as well as column widths. It would be recommended to create a seperate Web Part page to display this web part, so it can take up the full screen without the Quick Launch taking up room. This should also print rather nicely, too.

Development only took me around 2 hours, which is rather good for me…

Here’s a screenshot of the finished product in action 🙂

14 thoughts on “Year-To-View with Sharepoint Calendar

Leave a Reply

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