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

Published 05-01-2019 03:40 PM 203 Views
Microsoft

First published on TECHNET on Mar 25, 2013

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!

%3CLINGO-SUB%20id%3D%22lingo-sub-509760%22%20slang%3D%22en-US%22%3EHOW%20TO%3A%20Programmatically%20delete%20a%20single%20instance%20of%20a%20recurring%20event%20in%20a%20SharePoint%20calendar%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-509760%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20Mar%2025%2C%202013%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThis%20blog%20post%20is%20a%20contribution%20from%20Kevin%20Jacob%20Kurian%2C%20an%20engineer%20with%20the%20SharePoint%20Developer%20Support%20team.%3C%2FP%3E%0A%3CP%3EWhen%20we%20edit%20a%20single%20instance%20of%20a%20recurring%20event%2C%20it%20actually%20creates%20a%20new%20instance%20of%20the%20event%20and%20deletes%20the%20old%20one.%26nbsp%3B%20The%20old%20instance%20is%20deleted%20by%20setting%20certain%20attributes%20of%20that%20particular%20instance.%26nbsp%3B%20This%20is%20per%20design.%3C%2FP%3E%0A%3CP%3EHere%E2%80%99s%20an%20example%20of%20deleting%20a%20single%20instance%20of%20a%20recurring%20event%3A%3C%2FP%3E%0A%3CDIV%20id%3D%22codeSnippetWrapper%22%3E%0A%3CDIV%20id%3D%22codeSnippet%22%3ESPListItem%20deleting_item%20%3D%20list.Items.Add()%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Edeleting_item%5B%22MasterSeriesItemID%22%5D%20%3D%20olditem.ID%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Edeleting_item%5B%22UID%22%5D%20%3D%20olditem%5B%E2%80%9CUID%E2%80%9D%5D%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%2F%2F%20EventType%20is%20the%20attribute%20that%20defines%20that%20this%20event%20is%20to%20be%20deleted%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Edeleting_item%5B%22EventType%22%5D%20%3D%203%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%2F%2F%20fRecurrence%20identifies%20that%20the%20event%20is%20a%20recurring%20event%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Edeleting_item%5B%22fRecurrence%22%5D%20%3D%201%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Edeleting_item%5B%22fAllDayEvent%22%5D%20%3D%20olditem%5B%22fAllDayEvent%22%5D%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Edeleting_item%5B%22EventDate%22%5D%20%3D%20olditem%5B%22EventDate%22%5D%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Edeleting_item%5B%22EndDate%22%5D%20%3D%20olditem%5B%22EndDate%22%5D%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%2F%2F%20Set%20RecurrenceID%20this%20to%20the%20date%20of%20the%20event%20instance%20you%20want%20to%20delete%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Edeleting_item%5B%22RecurrenceID%22%5D%20%3D%20olditem%5B%22EventDate%22%5D%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%2F%2F%20the%20%E2%80%9CDeleted%3A%E2%80%9D%20keyword%20is%20required%20in%20the%20Title%20of%20the%20deleting%20instance%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Edeleting_item%5B%22Title%22%5D%20%3D%20%22Deleted%3A%20%22%20%2B%20olditem%5B%22Title%22%5D.ToString()%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Edeleting_item.Update()%3B%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Elist.Update()%3B%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3EHTH!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-509760%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20TECHNET%20on%20Mar%2025%2C%202013%20This%20blog%20post%20is%20a%20contribution%20from%20Kevin%20Jacob%20Kurian%2C%20an%20engineer%20with%20the%20SharePoint%20Developer%20Support%20team.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-509760%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Sep 01 2020 02:23 PM
Updated by: