Sdílet prostřednictvím


HOW TO: Programmatically delete a single instance of a recurring event in a SharePoint calendar

This blog post is a contribution from Kevin Jacob Kurian, an engineer with the SharePoint Developer Support team.

When we edit a single instance of a recurring event, it actually creates a new instance of the event and deletes the old one.  The old instance is deleted by setting certain attributes of that particular instance.  This is per design.

Here’s an example of deleting a single instance of a recurring event:

 SPListItem deleting_item = list.Items.Add();
 deleting_item["MasterSeriesItemID"] = olditem.ID;
 deleting_item["UID"] = olditem[“UID”];
  
 // EventType is the attribute that defines that this event is to be deleted
 deleting_item["EventType"] = 3;
  
 // fRecurrence identifies that the event is a recurring event
 deleting_item["fRecurrence"] = 1;
 deleting_item["fAllDayEvent"] = olditem["fAllDayEvent"];
 deleting_item["EventDate"] = olditem["EventDate"];
 deleting_item["EndDate"] = olditem["EndDate"];
  
 // Set RecurrenceID this to the date of the event instance you want to delete
 deleting_item["RecurrenceID"] = olditem["EventDate"];
  
 // the “Deleted:” keyword is required in the Title of the deleting instance
 deleting_item["Title"] = "Deleted: " + olditem["Title"].ToString();
 deleting_item.Update();
 list.Update();

HTH!

Comments

  • Anonymous
    June 11, 2013
    the code that you provided is not working, the selected event is not getting deleted.

  • Anonymous
    November 02, 2015
    Just tried it and it works for me.
    Saved me a lot of time to undestand how SharePoint does it.
    Thx a lot !

  • Anonymous
    June 29, 2016
    It is not working for All day recurring events , for other recurring event it is working fine.Please reply if you got the solution for All day recurring events.Thanks in advance.