Pages

Subscribe:

Monday, September 10, 2012

Checking Whether an Item Is in a Set

We often need to know whether an item is already in a set.
public bool IsDocumentSetItem(SPListItem itemToCheck)
{
bool documentSetItem = false;
if (itemToCheck.File != null)
{
DocumentSet documentSet;
documentSet = DocumentSet.GetDocumentSet(itemToCheck.File.ParentFolder);
if (null != documentSet)
{
documentSetItem = true;
}
}
return documentSetItem;
}
The code asks the current item to return the containing set. If there is no set, then the item is not part of any document set.