Add content type from sandboxed solution to list definition (farm solution) does not work
-
09-12-2019 - |
Question
I'm using a sandboxed solution from a 3rd party vendor which contains some site columns and a site content type.
I want to add this content type to my document library definition in CAML.
But when I add a reference to this content type in my schema.xml like this:
<List ... EnableContentTypes="TRUE">
<MetaData>
<ContentTypes>
<ContentTypeRef ID="0x0101002EFF4F6709F446E5AD064DC20BBE6855" />
<!--contenttypeid of content type from sandboxed solution-->
<ContentTypeRef ID="0x0101" />
<!--contenttypeid of Document-->
...
</ContentTypes>
...
</MetaData>
</List>
The content type is not added to my library when I create an instance of it. (I created this document library after the sandboxed solution was activated of course)
Even worse in fact, I receive the following error message:
A duplicate content type name "Document" was found.
I've got reasons to believe that this is due to the fact that SP somehow cannot find the sandboxed content type and thinks it's a child content type of Document. So it adds the Document content type twice to my list with this error message as a result.
I just don't understand why it is not adding the content type from the sandboxed solution?
After all I can see this content type in the site (collection) content types gallery and I am able to add the content type via the UI to the same document library without a reference to this "sandboxed" content type.
UPDATE: I've tried to only add the 3rd party vendors's content type to the document library definition and now only 1 "Document" content type is added.
Actually it creates a list content type called "Document" which inherits from the 3rd party vendor's site content type.
So the following List Content Type Information is displayed:
- Name: Document
- Description: Create a new Document
- Parent: {3rd party vendor's site content type}
And the site columns from the site content type were copied over.
Unfortunately it doesn't update the list content type's name.
Please share any clues you might have...
Solution
It seems that list has its own internal content type or at the very least, its own set of fields, which is creating the problem. Try investigating the list with the SharePoint Manager 2007/2010.
The alternative approach could be to use ContentTypeBinding
element to bind multiple ContentTypes.
<ContentTypeBinding
ContentTypeId="0x010100AA8705BBBC554342BC1396AB7FB723B401"
ListUrl="MyDocLibrary"
/>
<ContentTypeBinding
ContentTypeId="0x010100AA8705BBBC554342BC1396AB7FB723B402"
ListUrl="MyDocLibrary"
/>
<ContentTypeBinding
ContentTypeId="0x010100AA8705BBBC554342BC1396AB7FB723B403"
ListUrl="MyDocLibrary"
/>
ContentTypeBinding elements that are responsible for linking the multiple content types share a common parent i.e. 0x0101
, which means ancestor of this type is the base Document content type.