Programmatically set the Approval Status of a SharePoint ListItem

Background

I’m working on a project at the moment where the approval of a list item needs to be by a specific person based on the content of the item. Normally this would be a great opportunity to use some Workflow but for other reasons this was decided against.

This particular project is involving a lot of web service work due to the Infopath component, to this end it seemed prudent to use the Web Service to perform the approval action.

Approval Status

The approval status of List Item is held in the ModerationInformation property of the SPListItem object.

1
2
3
4
5
6
7
8
using (SPWeb web = listItem.Web())
{
      bool allowUpdates = web.AllowUnsafeUpdates;
      web.AllowUnsafeUpdates = true;
      listItem.ModerationInformation.Status = SPModerationStatusType.Approved;
      listItem.Update();
      web.AllowUnsafeUpdates = allowUpdates;
}

So updating the Approval is actually very easy. The options for SPModerationStatusType can be found on the following MSDN page for SPModerationStatusType.

Leave a comment