A DocSet is basically an SPListItem which is actually a folder. To work with Document Sets we need to add the reference for the following Namespaces:
- Microsoft.Office
- Microsoft.Office.DocumentManagement
- Microsoft.Office.DocumentManagement.DocumentSets
Now we will get all the documents sets in a document library using SharePoint Object Model. We will check each item in the document library to verify if it is a Document Set & if it is a document set we will get its property. We will find the Welcome Page URL, the name of the each document set, items inside a Document Set, and the fields shown in the Document Set Welcome Page.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office; using Microsoft.Office.DocumentManagement; using Microsoft.Office.DocumentManagement.DocumentSets; using Microsoft.SharePoint; using Microsoft.SharePoint.Portal; using Microsoft.SharePoint.Administration; namespace GettingDocSetsWithObjectModel { class DocSetDetails { static void Main(string[] args) { if (SPFarm.Local != null) { SPSite oSiteColl = new SPSite("http://SiteCollectionURL"); SPWeb oWeb = oSiteColl.OpenWeb(); SPFolder oFolder = oWeb.Folders["http://SiteCollectionURL/DocLibrary"]; SPDocumentLibrary oDocLib = oFolder.DocumentLibrary; foreach (SPListItem oItem in oDocLib.Items) { if (oItem.Folder != null) { DocumentSet oDocSet = DocumentSet.GetDocumentSet(oItem.Folder); if (oDocSet != null) { SPListItem oSpItem = oDocSet.Item; //This will get the Document Set Name Console.WriteLine("Docset Name: {0}", oSpItem["Name"].ToString()); //This will get the detail who has created the Document Set. Console.WriteLine("Created By: {0}", oSpItem["Created By"].ToString()); //This will show the Document Set Welcome Page. Console.WriteLine("WelcomePageUrl: {0}", oDocSet.WelcomePageUrl); //This will show the number of items in the document set. Console.WriteLine("ItemCount: {0}", oDocSet.Folder.ItemCount); //This will show the fields which are getting displayed in the Welcome page. Console.WriteLine("Welcomepage Fields:"); DocumentSetTemplate template = oDocSet.ContentTypeTemplate; WelcomePageFieldCollection fields = template.WelcomePageFields; foreach (SPField field in fields) { Console.WriteLine("{0}", field.Title); } Console.Read(); } } } } } } }
No comments:
Post a Comment