Monday 1 August 2011

Programmatically retrieve files in a DocumentSet in SharePoint 2010


To Programmatically retrieve files in a DocumentSet  First check if its a item or a Folder. Then check if its a DocumentSet of a SPFolder. At last Retrive the files in teh document set.
bool _isDocumentset = IsDocumentSet(_item);

public static bool IsDocumentSet(this SPListItem item)

{

bool documentSetItem = false;

DocumentSet documentSet = null;

if (null != item && item.IsFolder())

{

documentSet = DocumentSet.GetDocumentSet(item.Folder);

if (null != documentSet)

documentSetItem = true;

}

return documentSetItem;

}



3. If document set then get its files

if(isDocumentset)

{

SPFolder documentsetFolder = _item.Folder;

SPFile file = documentsetFolder.Files[0]; -> Get files

}

Ads by Google

No comments:

Post a Comment