Accessing a Document Set Programmatically SharePoint 2010

A document set is specific folder based on a custom content type that inherits from a built-in content type. The new API necessary to deal with document sets is added to the existing model without changing basic classes such as SPList or SPFolder. To access document set and its properties various functions are defined in the Microsoft.Office.DocumentManagement.DocumentSets namespace. However, the most valuable class is the DocumentSet class. This class has three static methods that you would need frequently:
• Create: Creates a new instance
• GetDocumentSet: Creates an existing instance from an SPFolder object
• Import: Imports a document from a stream or byte array into a folder

To see an example about how to create a document set see the post
Programatically creating document sets in SharePoint 2010

In this post we will see example where i am accessing the document set of an item and retrieving the document set's Welcome Page Fields.

SPListItem item = SPContext.Current.ListItem;

//The GetDocumentSet method is used to convert the technical base (SPFolder) into a more appropriate object type.
DocumentSet set = DocumentSet.GetDocumentSet(item.Folder);

Console.WriteLine("ContentType: {0}", item.ContentType.Name);
Console.WriteLine("Title: {0}", item.Title);

//Document set welcome page url
Console.WriteLine("WelcomePageUrl: {0}", set.WelcomePageUrl);
Console.WriteLine("ItemCount: {0}", set.Folder.ItemCount);
Console.WriteLine("Welcomepage Fields:");

//The ContentTypeTemplate property of the document set returns the template information as a DocumentSetTemplate type.

DocumentSetTemplate template = set.ContentTypeTemplate;

WelcomePageFieldCollection fields = template.WelcomePageFields;
foreach (SPField field in fields)
Console.WriteLine("{0}", field.Title);

For more on Document Sets see Programmatically adding documents to a document set sharepoint 2010


Post a Comment


This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at .

Copyright (c) 2010 @ All rights are reserved.Do Not Copy.

@ Learning