Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
General Reference
 How to: Add a Recurring Event to Li...

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
How to: Add a Recurring Event to Lists on Multiple Sites

This programming task shows how to add a recurring event with a Meeting Workspace site to the Events list of every site in a collection of subsites.

To add a recurring event with a Meeting Workspace site to the Events list of every site in a collection of subsites

  1. Create a console application in Microsoft Visual Studio 2005, as described in How to: Create a Console Application.

  2. Add a using or Imports directive to the opening of the .cs or .vb file for the Microsoft.SharePoint and Microsoft.SharePoint.Meetings namespaces, as follows:

    Visual Basic
    Imports Microsoft.SharePoint
    Imports Microsoft.SharePoint.Meetings
    

    C#
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Meetings;
    
  3. Use the SPSite constructor to instantiate a specified site collection. This example uses an indexer on the AllWebs property of the SPSite class to return a specific site, and the Webs property of the SPWeb class to return the collection of subsites beneath the site. Set up a foreach loop to iterate through all the subsites and obtain the Events list for each site and the collection of list items in each Events list, as follows:

    Visual Basic
    Dim evtTitle As String = Console.ReadLine()
    
    Dim siteCollection As New SPSite("Absolute_Url")
    Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
    Dim subSites As SPWebCollection = site.Webs
    Dim subSite As SPWeb
    
    For Each subSite In subSites
    
        Dim list As SPList = subSite.Lists("Events")
        Dim listItems As SPListItemCollection = list.Items

    C#
    string evtTitle = Console.ReadLine();
    
    SPSite siteCollection = new SPSite("Absolute_Url");
    SPWeb site = siteCollection.AllWebs["Site_Name"];
    SPWebCollection subSites = site.Webs;
    
    foreach (SPWeb subSite in subSites)
    {
        SPList list = subSite.Lists["Events"];
        SPListItemCollection listItems = list.Items;
  4. Create a list item. This example uses the Add method of the SPListItemCollection class to create an uninitialized list item, uses indexers to set various properties for the new item, and then uses the Update method to finish creating the item.

    Visual Basic
    Dim recEvent As SPListItem = listItems.Add()
    
    Dim recdata As String 
            = "<recurrence><rule><firstDayOfWeek>su</firstDayOfWeek>" _ 
        & "<repeat><daily dayFrequency='1' /></repeat>" _ 
        & "<repeatInstances>5</repeatInstances></rule></recurrence>"
    
    recEvent("Title") = evtTitle
    recEvent("RecurrenceData") = recdata
    recEvent("EventType") = 1
    recEvent("EventDate") = New DateTime(2003, 8, 15, 8, 0, 0)
    recEvent("EndDate") = New DateTime(2003, 9, 25, 9, 0, 0)
    recEvent("UID") = Guid.NewGuid()
    recEvent("TimeZone") = 13
    recEvent("Recurrence") = - 1
    recEvent("XMLTZone") 
            = "<timeZoneRule><standardBias>480</standardBias>" _
        & "<additionalDaylightBias>-60</additionalDaylightBias>" _
        & "<standardDate><transitionRule  month='10' 
            day='su' weekdayOfMonth='last' />" _
        & "<transitionTime>2:0:0</transitionTime></standardDate>" _
        & "<daylightDate><transitionRule  month='4' 
            day='su' weekdayOfMonth='first' />" _
        & "<transitionTime>2:0:0</transitionTime>
            </daylightDate></timeZoneRule>"
    
    recEvent.Update()
    

    C#
        SPListItem recEvent = listItems.Add();
    
        string recData = "<recurrence><rule>
                <firstDayOfWeek>su</firstDayOfWeek>" +
            "<repeat><daily dayFrequency='1' /></repeat>" +
            "<repeatInstances>5</repeatInstances></rule></recurrence>";
    
        recEvent["Title"] = evtTitle;
        recEvent["RecurrenceData"] = recData;
        recEvent["EventType"] = 1;
        recEvent["EventDate"] = new DateTime(2003,8,15,8,0,0);
        recEvent["EndDate"] = new DateTime(2003,9,25,9,0,0);
        recEvent["UID"] = System.Guid.NewGuid();
        recEvent["TimeZone"] = 13;
        recEvent["Recurrence"] = -1;
        recEvent["XMLTZone"] = "<timeZoneRule>
                <standardBias>480</standardBias>" +
            "<additionalDaylightBias>-60</additionalDaylightBias>" +
            "<standardDate><transitionRule  month='10' 
                day='su' weekdayOfMonth='last' />" +
            "<transitionTime>2:0:0</transitionTime></standardDate>" +
            "<daylightDate><transitionRule  month='4' 
                day='su' weekdayOfMonth='first' />" +
            "<transitionTime>2:0:0</transitionTime>
                </daylightDate></timeZoneRule>";
    
        recEvent.Update();
    

    The recData variable contains an XML fragment that specifies properties for a recurring event taking place daily for five days, and the XMLTZone indexer assigns time zone information for the current site. The XML that defines the recurrence and specifies the time zone information is contained in the ntext3 and ntext4 columns of the UserData table in the content database.

    The following table shows examples of the different kinds of recurrence that can be used.

    Description Example

    Every other day until a specified end date

    <recurrence><rule>
       <firstDayOfWeek>su</firstDayOfWeek>
       <repeat><daily dayFrequency='2' 
          /></repeat>
       <windowEnd>2003-09-
          20T09:00:00Z</windowEnd>
    </rule></recurrence>

    Weekly on Monday

    <recurrence><rule>
       <firstDayOfWeek>su</firstDayOfWeek>
       <repeat><weekly mo='TRUE' 
          weekFrequency='1' /></repeat>
       <repeatForever>FALSE</repeatForever>
    </rule></recurrence>

    Every two months on the third day for five sessions

    <recurrence><rule>
       <firstDayOfWeek>su</firstDayOfWeek>
       <repeat><monthly monthFrequency='2'
          day='3' /></repeat>
       <repeatInstances>5</repeatInstances>
    </rule></recurrence>

    Monthly on the first Tuesday until a specified end date

    <recurrence><rule>
       <firstDayOfWeek>su</firstDayOfWeek>
       <repeat>
          <monthlyByDay tu='TRUE' 
             weekdayOfMonth='first' 
             monthFrequency='1' />
       </repeat>
       <windowEnd>2003-08-
          02T10:00:00Z</windowEnd>
    </rule></recurrence>

    Yearly on the twentieth day of the ninth month until a specified end date

    <recurrence><rule>
       <firstDayOfWeek>su</firstDayOfWeek>
       <repeat><yearly yearFrequency='1' 
          month='9' day='20' /></repeat>
       <windowEnd>2007-09-
          20T07:00:00Z</windowEnd>
    </rule></recurrence>
  5. To add a Meeting Workspace site to the recurring event, use one of the Add methods of the SPWebCollection class and the LinkWithEvent method of the SPMeeting class.

    Visual Basic
        Dim mwsSites As SPWebCollection = subSite.Webs
    
        Dim path As String = recEvent("Title").ToString()
    
        Dim newSite As SPWeb = mwsSites.Add(path, "Workspace_Name", _
            "Description", Convert.ToUInt32(1033), "MPS#0", False, 
            False)
    
        Dim mwsSite As SPMeeting 
            = SPMeeting.GetMeetingInformation(newSite)
    
        Dim guid As String = list.ID.ToString()
        Dim id As Integer = recEvent.ID
    
        Try
    
            mwsSite.LinkWithEvent(subSite, guid, id, "WorkspaceLink", 
                "Workspace")
    
        Catch ex As System.Exception
    
            Console.WriteLine(ex.Message)
    
        End Try
    
    Next subSite

    C#
        SPWebCollection mwsSites = subSite.Webs;
    
        string path = recEvent["Title"].ToString();
    
        SPWeb newSite = mwsSites.Add(path, "Workspace_Name", 
            "Description", 1033, "MPS#0", false, false);
    
        SPMeeting mwsSite = SPMeeting.GetMeetingInformation(newSite);
    
        string guid = list.ID.ToString();
        int id = recEvent.ID;
    
        try
        {
            mwsSite.LinkWithEvent(subSite, guid, id, "WorkspaceLink", 
                "Workspace");
        }
    
        catch (System.Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

    After the Meeting Workspace site is created, the GetMeetingInformation method returns an SPMeeting object representing the site.

  6. Press F5 to start the Console Application.

  7. At the command prompt, type a name for the Meeting Workspace site, and then press ENTER to add a recurring event with a Meeting Workspace site to the Events list in all the subsites beneath a site.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Wrong location of this article      geovar   |   Edit   |   Show History

The article above has nothing to do with Event Handlers, but with Events list. It should be placed under Sample Object Model Tasks

Tags What's this?: Add a tag
Flag as ContentBug
Where is the API / documentation on Recurring Events?      mafuba   |   Edit   |   Show History
This is a very sore topic that has plagued me for years now. Where is the API, or if it's not in the API, the documentation on dealing with recurrence within SharePoint?
Tags What's this?: Add a tag
Flag as ContentBug
How do you retrieve recurring events from a list      nn101   |   Edit   |   Show History
When I use the SPListItemCollection it does not return the recurring events. SPQuery has an ExpandRecurring property which does not return the recurring events either!!
Tags What's this?: Add a tag
Flag as ContentBug
Unable to implement      Gamper   |   Edit   |   Show History
I was unablet to get the recurrence to work. The calendar shows it as a single event, and even though the list view shows it as a recurring event, the recurrence pattern shows up as "custom" when it should show as weekly. Has anyone gotten this working? Has Msft posted documentation on manipulating recurring events via the Object Model yet?
Tags What's this?: Add a tag
Flag as ContentBug
Event creation ok, issues updating end dates for existing Events      wbryan   |   Edit   |   Show History

The sample appears to work when creating a new recurring event, but I have come across a problem updating the EndDate for existing events. Does anyone know the correct procedure to do this? There appears to be a bug in the calculation of the event Duration field that occurs when you want to extend the windowEnd date and also try to change the EndDate to match how the SharePoint UI stores data during an update. The duration field gets calculated for the entire event window.

Tags What's this?: Add a tag
Flag as ContentBug
Recurrent Event created but not display in Calendar View      Ponte83   |   Edit   |   Show History
I've added the event to a calendar list and I can see it in All Event View, but in Calendar View there is no event there. Does someone know why? I think there's something wrong with the date fields...but that's only my lucky guest, I really dont know whats causing this.
Tags What's this?: Add a tag
Flag as ContentBug
Please redirect questions to forums      Noelle Mallory - MSFT   |   Edit   |   Show History
Please do not post questions in Community Content per the FAQ. Questions should be posted to the MSDN Forums at http://forums.microsoft.com/msdn.
Tags What's this?: Add a tag
Flag as ContentBug
The code sample provided works but      schaffs007   |   Edit   |   Show History
There's always a butt - the value placed in the XMLTZone field matters greatly - my suggestion using SQL Management Studio or the like query the content db for your site/sitecolelction to see the correct value to use for your site collection/site/list - you are required to use the correct value to make the item actually show up as a recurring item - I have found a copy of the Lists Web Service Protocol specification and found a field labeled TimeZone which appears to be a timeZoneRule StandardBias as opposed to a timezone - this is available via the GetList function of the Lists web service.
Tags What's this?: Add a tag
Flag as ContentBug
Make sure to dispose of your SPSites and SPWebs      austegard   |   Edit   |   Show History
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker