I would like to get all the moderation status of a list item in a deleting event. I have enabled 'versioning'.
If the item approved once, the item should not be deleted, this is my requirement.
- Edited by Orange33 Tuesday, August 18, 2015 7:14 AM
Technology Tips and News
I would like to get all the moderation status of a list item in a deleting event. I have enabled 'versioning'.
If the item approved once, the item should not be deleted, this is my requirement.
Hi,
We can get all the list item versions, then check it. The following code snippet for your reference:
public override void ItemDeleting(SPItemEventProperties properties) { SPListItem listItem = properties.ListItem; SPListItemVersionCollection listItemVersions = listItem.Versions; if (listItemVersions != null && listItemVersions.Count > 0) { foreach (SPListItemVersion item in listItemVersions) { if (item["_ModerationStatus"]!=null && "0".Equals(item["_ModerationStatus"].ToString())) { properties.Status = SPEventReceiverStatus.CancelWithError; properties.ErrorMessage = "Cannot delete data"; } } } }
Best Regards,
Dennis