User Tools

Site Tools


notes:sharepoint2010:documentset

DocumentSets in SharePoint 2010

Download a document set:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using Microsoft.SharePoint;
using Microsoft.Office.DocumentManagement.DocumentSets;
 
...
 
SPListItem currentItem = SPContext.Current.ListItem;
DocumentSet currentDocset = DocumentSet.GetDocumentSet(currentItem.Folder);
 
this.Page.Response.ContentType = "application/zip";
currentDocset.Export(this.Page.Response.OutputStream, 1024);
 
this.Page.Response.End();

Check if a content type derives from DocumentSet:

// The contentTypeHex is a hexadecimal representation of the content type we are testing.
SPContentTypeId contentTypeId = new SPContentTypeId(contentTypeHex);
 
if (contentTypeId.IsChildOf(SPBuiltInContentTypeId.DocumentSet))
{
    // ... the content type derives from DocumentSet
}
else
{
    // ... the content type does not derive from DocumentSet
}

Obtain a DocumentSet from a list item folder.

// myListItem is of type SPListItem.
SPFolder folder = myListItem.Folder;
if (folder == null)
{
    // a folder must exist
    // ...
}
else
{
    DocumentSet docSet = DocumentSet.GetDocumentSet(folder);
    // ...
}

Add comments to a DocumentSet:

docSet.VersionCollection.Add(true, comments);

Create a list containing information about all DocumentSets in a library 'lib':

// A custom class to keep DocumentSet info.
class DocSetInfo
{
    public int ID { get; set; }
    public string Title { get; set; }
    public string Url { get; set; }
}
...
List<DocSetInfo> sets = new List<DocSetInfo>();
 
// Add document sets to a collection.
foreach (SPListItem item in lib.Items)
{
    bool isDocSet = item.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.DocumentSet);
 
    if (isDocSet)
    {
        sets.Add(new DocSetInfo { ID = item.ID, Title = item.Title, Url = item.Url });
    }
}
notes/sharepoint2010/documentset.txt · Last modified: 2020/08/26 (external edit)