SharePoint Global Calendar

Posted: October 4th, 2009 | Author: | Filed under: SharePoint | Tags: , | No Comments »

A centralized calendar is a great feature to have for portals or collaboration workspaces, however, there is no default way to achieve this in WSS without a third party solution.

Gunnar Peipman has an excellent article on creating a SharePoint global calendar using site data query and calendar view control. I have slightly modified the code to allow the Global Calendar web part to query all SharePoint event list and I have added a custom field in SharePoint which will determine if the list item will display on our global calendar web part.

You can visit Gunnar Peipman’s blog to view the entire code I will list sections of the original code and modifications I have made.

When querying list one method is to query each list to query like:

private DataTable GetQueryData(SPWeb web)
{
    var query = new SPSiteDataQuery();

     query.Lists = @"<Lists>
                        <List ID='{56F5E040-D547-4BF5-8C99-F019D54F9997}' />
                        <List ID='{92A87CB9-E39B-4C2D-B37D-5721E6C7FECD}' />
                    </Lists>";

    query.Query = @"<Where>
                        <Gt>
                            <FieldRef Name='ID' />
                            <Value Type='Number'>0</Value>
                        </Gt>
                    </Where>";

    query.Webs = "<Webs Scope='SiteCollection' />";

    query.ViewFields = "<FieldRef Name='Title' />";
    query.ViewFields+= "<FieldRef Name='ID' />";
    query.ViewFields+= "<FieldRef Name='EventDate' />";
    query.ViewFields+= "<FieldRef Name='EndDate' />";
    query.ViewFields+= "<FieldRef Name='Location' />";
    query.ViewFields+= "<FieldRef Name='Description' />";
    query.ViewFields+= "<FieldRef Name='fRecurrence' />";

    query.RowLimit = 100;

    return web.GetSiteData(query);
}

This will query the list with the specified GUIDs and you can enter the GUID for each list you would like to query. In one instance I was working on a  setup  where new collaboration workspaces were always being created,in this case to avoid modifying the code each time I queried the event list template ID by replacing

query.Lists = @"<Lists>
                        <List ID='{56F5E040-D547-4BF5-8C99-F019D54F9997}' />
                        <List ID='{92A87CB9-E39B-4C2D-B37D-5721E6C7FECD}' />
                    </Lists>";

with
query.Lists = @"<List>

                         <List ServerTemplate=’106’/ >

                <List>”

which will query every event  list in the site collection and the calendar will display items from every event list up to the query row limit that is set.

Since this limits the control I have on what gets returned I have taken this one step further by creating a new content type named “Global Calendar Content type” with the Event content type as the parent. In this content type I have added an additional column titled “Display on Global Calendar”  and allowed this content type in the source calendars ( you can follow the instructions here to unhide the event content type and follow the instructions here for adding a content type to a library or list.)

gcal

I will now modify this code to check if the “Display on Global Calendar” column is checked , if it is then the item is displayed on the Global Calendar web part, with the two changes they query section of the code now looks like this

private DataTable GetQueryData(SPWeb web)
{
    var query = new SPSiteDataQuery();

     query.Lists = @"<Lists>

                       <Lists ServerTemplate='106'/>

                    </Lists>";
    query.Query = @"<Where>
                        <Eq>
                            <FieldRef Name=’Display_x0020_on_x0020_Global_x0’/>
                            <Value Type='Boolean'>1</Value>
                        </Eq>
                    </Where>";

    query.Webs = "<Webs Scope='SiteCollection' />";

    query.ViewFields = "<FieldRef Name='Title' />";
    query.ViewFields+= "<FieldRef Name='ID' />";
    query.ViewFields+= "<FieldRef Name='EventDate' />";
    query.ViewFields+= "<FieldRef Name='EndDate' />";
    query.ViewFields+= "<FieldRef Name='Location' />";
    query.ViewFields+= "<FieldRef Name='Description' />";
    query.ViewFields+= "<FieldRef Name='fRecurrence' />";

    query.RowLimit = 100;

    return web.GetSiteData(query);
}

Get the entire code from the blog posting creating a SharePoint global calendar then make the modifications listed in this article and compile and deploy the code to your server. The final result will be a calendar view web part and it should pull results from all event list items in the site collection where you are using the new content type and have checked the custom “Display on Global Calendar” column.

I have attached a solution for the web part and the content type. Source code is also available.

Global Calendar Installation Global Calendar Source

I have tested the web parts in Moss 2007  the downloads are provided “As is” with no warranties of any kind.

Be Sociable, Share!

Related posts:

  1. Customizing the SharePoint ECB with Javascript
  2. Modify the SharePoint Wiki Interface


Leave a Reply