Hi all,
I had an event list. I created a new item that has recurrence daily ( Start Time : 1/5/2010 12 : 00 AM and End Time : 5/30/2010 12:00 AM). I want to delete the item which has Start Time : 5/12/2010 12:00 AM but my application throwed exception.
My code as below :
DateTime eventDate = DateTime.Parse(list.Fields.GetFieldByInternalName("EventDate").GetFieldValueAsHtml(DateTime.Parse(this.DateTimeOfItem).ToUniversalTime()));
SPQuery pQuery = new SPQuery();
pQuery.ExpandRecurrence = true;
pQuery.CalendarDate = eventDate.AddDays(-1);
pQuery.Query = string.Format("<OrderBy><FieldRef Name=\"EventDate\"/></OrderBy><Where><And><DateRangesOverlap><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"RecurrenceID\" /><Value Type=\"DateTime\"><Week /></Value></DateRangesOverlap><Eq><FieldRef Name=\"ID\" /><Value Type=\"Counter\">{0}</Value></Eq></And></Where>", this.ID);
SPListItemCollection itemColl = list.GetItems(pQuery);
int index = 0;
while (index < itemColl.Count)
{
SPListItem item = itemColl[index];
if (DateTime.Parse(item["EventDate"].ToString()).CompareTo(eventDate) == 0)
{
web.AllowUnsafeUpdates = true;
item["UID"] = Guid.NewGuid().ToString();
item["EventType"] = 3;
item["RecurrenceID"] = eventDate;
item["MasterSeriesItemID"] = this.ID;
item["XMLTZone"] = null;
item["RecurrenceData"] = "Every 1 day(s)";
item.Update();
list.Update();
web.AllowUnsafeUpdates = false;
break;
}
index++;
}
I do not know why I can not update this item. Please help me.
Thanks
PD.