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.
- I don't how to convert these recurrence event to a separated item. ( day by day)
- 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
};
startFiedld = eventdate
,endField = Enddate
, andtitleField = title
.