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.

Tuesday, February 16, 2010

Workflows in SharePoint 2010

I thought of sharing what I found with workflows in SharePoint 2010 today as all the others using the object model to associate the workflows to lists or list items will face the same night mare.

The main problem may be a bug in beta and hopfully MS will fix this in the final release. The problem is, we can get the workflow template collection using the workflow manager in 2007 using WorkflowManager.GetWorkflowTemplatesByCategory(). but this does not return the workflow template collection in 2010.

The work around I found is, in 2010, SPWeb.WorkflowTemplates is working and which is returning the workflow template collection for the given web. So we can use this property and get the workflow template collection for the root web of the site or any web as it does in WorkflowManager.GetWorkflowTemplatedByCategory().

I hope this will be fixed in the final release so that we can use the workflow manager to get the workflow template collection but certainly I do not see any difference in using SPWeb property also. I hope MS will have some kind of a better explaination for this behaviour.