Saturday, October 17, 2009

Content Approval for Folders

Scenario:
We had content approval enabled for one of our list items, since Folder itself is nothing more than ab item in the list, when user creates a folder it was asking for Approval.

Solution:
Users wanted Folders to be auto approved. Item Event Receiver took care of it.

You can reuse this code to approve any specific type of Content Type items.

Code:

public override void ItemAdded(SPItemEventProperties properties)
{

SPWeb web = properties.OpenWeb();

SPList list = properties.ListItem.ParentList;

SPListItem currentItem = properties.ListItem;

string itemCT = currentItem[list.Fields["Content Type"].InternalName].ToString();

if (itemCT == "Folder")
{

DisableEventFiring();

// Set the value to 0 to set it to Approved

currentItem[list.Fields["Approval Status"].InternalName] = "0";
currentItem.SystemUpdate();

EnableEventFiring();

}

0 comments: