Advertisement
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;
}
}
}
}
Great Article.. Thanks to share this...
ReplyDeleteThanks santosh!!
Delete