Monday, February 22, 2010

How do I know whether the list item is in a DocumentSet.

Document sets in SharePoint 2010 is a cool feature and while I was exploring the power of the document sets, I wanted to find out whether a given list item in a document library, is part of the document set or not. We might need to make this kind of decisions in event receivers.

I publish this in SharePoint forum and found a better way to do that thanks to Steve Curran, this is the link to the original thread in the forum.

http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/bfac0310-6efd-4855-a9f6-11b8ffdc35b1/#f260d5ef-4947-4148-b91a-c52e59aba047

I decided to share this information here also as I did not find any lead while googling. Hoping this will provide some kind of a lead for the others who are after similar solutions.

Start the real stuff, this interesting functionality is available in Microsoft.Office.DocumentManagement.dll, there is a separate name for document sets called
Microsoft.Office.DocumentManagement.DocumentSets. Using this you can write..

public bool IsDocumentSetItem(SPListItem itemToCheck)
{
bool documentSetItem = false;
DocumentSet documentSet = null;

if (null != itemToCheck)
{
if (null != itemToCheck.File)
{
documentSet = DocumentSet.GetDocumentSet(itemToCheck.File.ParentFolder);

if (null != documentSet)
{
documentSetItem = true;
}
}
}

return documentSetItem;
}


I wish to have this as a property of SPFolder but the DocuemntSet class is handy also.

No comments: