0

In my project, i will create a custom calendar to show events which come from some different sharepoint standard calendar. The logic of my calendar is that it will ask event list (next or previous month) from those SP calendar when user click next or prev button.

However, i don't know how to handle all recurrence event.

when i am trying to read a recurrence event, it will show something like <recurrence><rule><firstDayOfWeek>su</firstDayOfWeek><repeat><weekly mo="TRUE" th="TRUE" sa="TRUE" weekFrequency="3" /></repeat><repeatInstances>30</repeatInstances></rule></recurrence>

the above result bring 2 problems.

  1. I don't how to convert these recurrence event to a separated item. ( day by day)
  2. I cannot get that event when i click prev button because the recurrence will show as one event (the start date own all other recurrence event) in SharePoint.

For example:

I create an event which is recurrence in Every 3 week(s) on: Monday, Thursday, Saturday which end after 50 occurrences.

In program, the above event will represent in one SPListItem. However, i want the above event will separate in 50 event which has the same title but different start date and end date.

Code:

SPListItemCollection listItems = list.Items;
                    if (item["RecurrenceData"] != null)
                    {
                        XmlDocument xmlDoc = new XmlDocument();
                        var  recurrenceData = item["RecurrenceData"].ToString();
                        myfunctionLog("recurrenceData: " + recurrenceData)
                        xmlDoc.LoadXml(recurrenceData);
                        string xpath = "recurrence/rule";
                        var nodes = xmlDoc.SelectNodes(xpath);
                        foreach (XmlNode childrenNode in nodes)
                        {
                            myfunctionLog("Event: " + item["Title"].ToString());
                            myfunctionLog("Start from " + childrenNode.SelectSingleNode("//firstDayOfWeek").InnerText);
                        }
                    }

Update for spquery

                    DateTime ts = DateTime.Now;
                    query = new SPQuery(spview)
                    {
                        Query =
                        @"
                                    <OrderBy>
                                    <FieldRef Name='" + startField+"' Ascending='True' />"+
                                    "</OrderBy>",
                        ViewFields = @"<FieldRef Name='" + titleField + "'/>" +
                                      "<FieldRef Name='" + startField + "' />" +
                                      "<FieldRef Name='" + endField + "' />" +
                                      @"<FieldRef Name='fRecurrence' />
                                    <FieldRef Name='fAllDayEvent' />
                                    <FieldRef Name='RecurrenceData' />
                                    <FieldRef Name='Location' />",
                        ExpandRecurrence = true,
                        CalendarDate = ts
                    };
  • Have you tried adding 'ExpandRecurrence' property to your query? – Aveenav Jan 3 '17 at 15:12
  • i have tried to set ExpandRecurrence to true of the spquery, however, it also return the recurrence as one splistitem to me :( – king yau Jan 4 '17 at 7:28
  • can you post your spquery? – Aveenav Jan 4 '17 at 15:50
  • @Aveenav I have updated my post for the spquery. the startFiedld = eventdate, endField = Enddate, and titleField = title. – king yau Jan 5 '17 at 1:45
  • I think DateRangesOverlap is needed, try the caml query posted by @madhav – Aveenav Jan 5 '17 at 15:09
0

try this camlQuery

var queryForEvents = new SPQuery
    {
     ExpandRecurrence = true,
     Query = @"<Where><DateRangesOverlap><FieldRef Name='EventDate' />
     <FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' /><Value Type='DateTime'>
     <Now /></Value></DateRangesOverlap></Where><OrderBy><FieldRef Name='EventDate' Ascending='True' /></OrderBy>",

     ViewFields ="<FieldRef Name='Title' LinkToItem='TRUE'/><FieldRef Name='EventDate' />
     <FieldRef Name='EndDate' /><FieldRef Name='fRecurrence' /><FieldRef Name='RecurrenceData' /><FieldRef Name='Location' />
     <FieldRef Name='EventType' /><FieldRef Name='MasterSeriesItemID' />"
    };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.