Document sets Allowed Content types
-
Wednesday, February 22, 2012 2:00 AM
I have a document library with three content types. One of them is a document set type. I'm trying to add a custom content type to the document set in code but not having much luck. The document library is provisioned in a feature and the code to update the document set template runs in the feature receiver but doesn't work from there (no error is thrown during feature activation only when creating a document set). I've also tried running the code at the document library ItemAdded event for when creating a document set with the same results.
The code (ItemAdded) adding a document set to the document library
var docSetCT = properties.ListItem.ContentType;
var aCustomDocCt = properties.List.ContentTypes["CustomDocType"];
var docSetTemplate = DocumentSetTemplate.GetDocumentSetTemplate(docSetCT);
docSetTemplate.AllowedContentTypes.Add(aCustomDocCt.Id);
docSetTemplate.Update(false);
The code doesn't throw any errors, but it attempting to create the document set will throw an error to the effect of object cannot be null?I can do this in the UI, so that only my content type is placed in the allowed content types list with no default docs. Attempting to do this using Declaritive code has no effect.
<XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/allowedcontenttypes">
<act:AllowedContentTypes xmlns:act="http://schemas.microsoft.com/office/documentsets/allowedcontenttypes" LastModified="02/21/2012 05:19:46">
<AllowedContentType id="0x0101007BAF4627D37C5F4B891738DC43CEEE1B006B576ACCFD6644A68002DB27C47582E1" />
</act:AllowedContentTypes>
</XmlDocument>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/sharedfields">
<SharedFields xmlns="http://schemas.microsoft.com/office/documentsets/sharedfields" LastModified="1/1/1 0:00:01 AM" />
</XmlDocument>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/office/documentsets/defaultdocuments">
<DefaultDocuments xmlns="http://schemas.microsoft.com/office/documentsets/defaultdocuments" LastModified="1/1/1 0:00:01 AM" AddSetName="" />
</XmlDocument>
<XmlDocument NamespaceURI="Microsoft.SharePoint.Taxonomy.ContentTypeSync">
<SharedContentType xmlns="Microsoft.SharePoint.Taxonomy.ContentTypeSync" SourceId="a19f5828-1ea1-4f27-b9d7-a7844574eef1" ContentTypeId="0x0120D520006DC74F2F31E34F5887141D62950F5713" PreviousValue="false" />
</XmlDocument>
</XmlDocuments>This is my last resort.
All Replies
-
Wednesday, February 22, 2012 9:53 AM
Hi,
It does work through code / feature receiver. But it needs to be list provisioning or document set content type provisioning feature receiver.
I notice you are taking the document set content type from list. You change it like bellow and it will work.
string id = "0x0120D52000DocSetID";
SPContentTypeId ctId = new SPContentTypeId(id);
SPSite site = properties.Feature.Parent as SPSite;
SPContentType commDocSet = site.RootWeb.ContentTypes[ctId];
if (null == commDocSet)
{
throw new InvalidOperationException("Content Type not found for ID " + id);
}
DocumentSetTemplate documentSetTemplate = DocumentSetTemplate.GetDocumentSetTemplate(commDocSet);
documentSetTemplate.AllowedContentTypes.Clear();
documentSetTemplate.AllowedContentTypes.Add(new SPContentTypeId("0x010100ChildCTId"));// you may set welcome and shared fields here
documentSetTemplate.Update(true);
Regards
Yogesh Pawar
- Edited by Yogesh Pawar Wednesday, February 22, 2012 9:55 AM
-
Friday, February 24, 2012 8:30 AM
Nope. That doesn't work either.
The issue was that the document set content type was syndicated. i.e. lives in a content type hub.
When I placed the content type on the site root web it all worked. (shakes head).
Looks like updates made via the documentsettemplate doesn't work (maybe overriden) if the content type is syndicated. -
Thursday, May 03, 2012 6:47 PM
Hi Paul,
From what I know, when a syndicated document set content type is being modified on the local site, it causes problems with the document set template and allowed content type.
You should modify the document set template from the hub and then republish so all sites will be updated. When the local copy of the document set content type is changed, it will not update (might update for new document sets but not for already existing). Keeping the local copy as read only will help you not to do any changes.
Hope it helps.
JP Berube | MCTS SharePoint 2010 Configuration and Application Development

