Search This Blog

Wednesday, March 11, 2015

How to create document set programmatically in sharepoint 2010

In this Article I will explain how to create document set programmatically in sharepoint.
If you want to know to create document set Refer this link
We have to refer the two dlls

using System.Collections;
using Microsoft.Office.DocumentManagement.DocumentSets;

In Feature1.EventReceiver.cs I am writhing this code.


public class Feature1EventReceiver : SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
SPContentType docSetCT = web.ContentTypes["Document Set"];
SPDocumentLibrary Doclib = web.Lists.TryGetList("DocumentLibraryName"as SPDocumentLibrary;


if (docSetCT != null)
{
try
{
Hashtable props = new Hashtable();
props.Add("DocumentSetDescription""Sharepoint Related Documents");
SPFolder parentFolder = Doclib.RootFolder;
DocumentSet docSet = DocumentSet.Create(parentFolder, "SharePoint Documents", Doclib.ContentTypes.BestMatch(docSetCT.Id), props, true);


docSet.Item.ProgId = "SharePoint.DocumentSet";
//enabling the content type
Doclib.ContentTypesEnabled = true;
//enabling the versioning
Doclib.EnableVersioning = true;
Doclib.EnableMinorVersions = true;
Doclib.EnableModeration = true;

Doclib.Update();
docSet.Item.Update();
}
catch (Exception e)
{
throw e;
}

}
}


}
- See more at: http://www.dotnetsharepoint.com/2013/10/how-to-create-document-set.html#sthash.IMQjS4RZ.dpuf

No comments:

Post a Comment