none
[CAML Query] Getting Recurring Events in SharePoint Calendar RRS feed

Answers

  • Hi Charlie Wu,

    Have you tried the "Year" one for the DateRangesOverlap?
    I mean what i want is to get the past events that happen in this year. So I tried using the "Year", but the result is not what i want.

    But I already figure out a workaround, I use "Month" than looping it till it gets a Year. (since with "Month" I can get the past Events, not like the "Year").

    Anyway.. thanks for the help Charlie Wu & Karine Bosch.
    • Marked as answer by Chengyi Wu Thursday, September 3, 2009 7:39 AM
    Thursday, September 3, 2009 7:19 AM

All replies

  • You can workaround this by first getting all the recurring events and then filtering the results with a specific year.


    Keep It Simple and Stupid.
    • Proposed as answer by MARTISSE Thursday, February 18, 2010 9:45 AM
    Monday, August 31, 2009 9:26 AM
  • You can use the <Year /> element in your CAML query.

    You have to set the CAML query as follows:

    SPQuery query = new SPQuery();

    query.Query = "<Where><DateRangesOverlap><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"RecurrenceID\" /><Value Type=\"DateTime\"><Year /></Value></DateRangesOverlap></Where>"; 



    But also some properties of the SPQuery object:
     

    query.ExpandRecurrence = true;

    query.CalendarDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);


    Interesting URL:
    http://blogs.msdn.com/sharepoint/archive/2007/05/14/understanding-the-sharepoint-calendar-and-how-to-export-it-to-ical-format.aspx

    Karine

    Karine Bosch
    • Proposed as answer by MARTISSE Thursday, February 18, 2010 9:45 AM
    Monday, August 31, 2009 9:39 AM
  • @Charlie Wu & Karine Bosch

    Thanks for the reply, I already did that (based on the link that I posted above),
    but the result that i got are all the events that occurs starting from today all the way through 2011.
    (All the events i got start from September 1, 2009, I can't get the passed events (before September 1, 2009))

    • Proposed as answer by MARTISSE Thursday, February 18, 2010 9:45 AM
    Tuesday, September 1, 2009 2:37 AM
  • With proper manipulation of SPQuery CalendarDate and <value> of DateRangesOverlap, you can get past recurring events in expanded form.

    For e.g using below query I can get a recurring series expanded and get the constituents for the month of September 2008 :

    AFAIK, valid values for DateRangesOverlap are <Year>, <Month>, <Now>.

     

    using (SPSite oSPSite = new SPSite("http://localhost"))

                {

                    using (SPWeb oSPWeb = oSPSite.OpenWeb())

                    {

                        SPList list = oSPWeb.Lists["Calendar1"];

     

                        SPQuery query = new SPQuery();

     

                        query.ExpandRecurrence = true;

                        query.CalendarDate = new DateTime(2008,9,1);

     

                        query.Query = "<Where><DateRangesOverlap><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><Value Type=\"DateTime\"><Month /></Value></DateRangesOverlap></Where>";

                        SPListItemCollection listItems;

                        listItems = list.GetItems(query);

                        foreach (SPListItem items in listItems)

                        {

                            Console.WriteLine(items[3].ToString());                    }

                        Console.ReadLine();

     

                    }

                }


    Keep It Simple and Stupid.
    • Proposed as answer by MARTISSE Thursday, February 18, 2010 9:44 AM
    Wednesday, September 2, 2009 1:29 AM
  • Hi Charlie Wu,

    Have you tried the "Year" one for the DateRangesOverlap?
    I mean what i want is to get the past events that happen in this year. So I tried using the "Year", but the result is not what i want.

    But I already figure out a workaround, I use "Month" than looping it till it gets a Year. (since with "Month" I can get the past Events, not like the "Year").

    Anyway.. thanks for the help Charlie Wu & Karine Bosch.
    • Marked as answer by Chengyi Wu Thursday, September 3, 2009 7:39 AM
    Thursday, September 3, 2009 7:19 AM
  • Glad to hear you walk around this problem.
    Keep It Simple and Stupid.
    • Proposed as answer by MARTISSE Thursday, February 18, 2010 9:43 AM
    Thursday, September 3, 2009 7:39 AM
  • Thanks for the posts. Helped me query the calendar. I started using U2U caml builder to better understand how it works.

    @Chengyi Wu - Yes he did 'walk around' the problem like walking around a park! jk :)
    • Proposed as answer by MARTISSE Thursday, February 18, 2010 9:43 AM
    Wednesday, February 17, 2010 11:03 PM
  • To query 12 months before a date
    <Value Type='DateTime'>[2/17/2009 5:09:11 PM-12Month(s)]</Value>
    • Proposed as answer by MARTISSE Thursday, February 18, 2010 9:44 AM
    Wednesday, February 17, 2010 11:13 PM