I am writing code for creating DocumentSets
dynamically in one of my Document libraries in a SP2013 Community site.
SPContentType docSetCT = web.ContentTypes["Document Set"];
The above line always returns Null
and in turn the next line of codes error out.
I have activated the Document Set
feature at the site collection level.
The Community site is created by the same code, prior to the code line in concern.
The Document Library is also created in the same code, prior to the code line in concern.
I am able to get the object SPContentType docSetCT
, if i use AvailableContentTypes["Document Set"]
instead of ContentTypes["Document Set"]
. But, then i receive another error while creating the DocumentSet at following line of code.
docSet = DocumentSet.Create(docLibrary, docTitle, docSetCT.Id, docSetProperties);
I receive following error,
The content type "Folder" at "/" is sealed.
at Microsoft.SharePoint.SPContentType.Update(Boolean updateChildren, Boolean ignoreSealedOrReadOnly, Boolean throwOnSealedOrReadOnly, IList`1 exceptions) at Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet.ProvisionCTEventReceivers(SPContentType contentType) at Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet.<>c__DisplayClass7.b__5() at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass5.b__3() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet.Provision(Boolean bProvisionDefaultContent, SPLongOperationState longOperationState)
at Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet.Create(SPFolder parentFolder, String name, SPContentTypeId ctid, Hashtable properties, Boolean bProvisionDefaultContent, SPUser user, SPLongOperationState longOperationState) at Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet.Create(SPFolder parentFolder, String name, SPContentTypeId ctid, Hashtable properties, Boolean bProvisionDefaultContent) at JiveContentMigration.JiveContentMigrationWebpart.JiveContentMigrationWebpartUserControl.uploadDocumentToLibrary(SPWeb web, String docLibraryName, String folderName, String subFolderName, String jiveDocumentSummary, String jiveDocumentBodyText, DateTime createdOn, String docTitle)