All the moderation status of a list item

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
August 18th, 2015 7:14am

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

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 1:03am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics