Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Where should I "bind" content types to my list?

I need to bind two different custom content types. I tried to do it in the list definition but the changes did not take affect. Doing it next to the list instance did work, but would not work if i create a new list throe the web user interface.

Next to list instance

<ListInstance>
</ListInstance>
<ContentTypeBinding ContentTypeId="" ListUrl="">

Worked, but only for the created by the CAML definition.

Inside the list template

<List>
  <MetaData>
    <ContentTypes>
      <ContentTypeRef ID=""/>

This did not work. Anything special to think of here?

Add them through an Event receiver

One method I came to my mind, that I haven't tried yet, is to add the content types whit an event receiver when creating the list? It should work but feels more complicated than using CAML.

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

The correct place is the list template (schema.xml). But you have to repeat the FileRef inside the ContentTypeRef element from the content type definition and also copy all the fields to the Fields section in the schema.xml. Then to get the list created properly you must create a new list instance after you have deployed the updated list schema.

Unfortunately you cannot simply link the list definition to a content type.

Here is a stripped down example:

 <List>
  <MetaData>
    <ContentTypes>
      <ContentType ID="0x0100..." Name="...">
        <FieldRefs>
          <FieldRef ID="{993DAADB-918B-4AA1-89F4-34F0B57FD058}" Name="Some Field" />
        </FieldRefs>
      </ContentType>
    </ContentTypes>
    <Fields>
      <Field ID="{993DAADB-918B-4AA1-89F4-34F0B57FD058}" Name="Some Field" />
share|improve this answer
    
I tried very similar approaches and also this I think, but none worked. What you are doing above, is it not so that you actually define a new content type, and not refer to an old one? Do you know if your approach works for adding two content types also? Thanks for helping! –  Tim Sep 14 '11 at 8:01
    
No this does not create a new content type. The 'issue' with SharePoint is that you must have a copy of the content type in the list definition. This is counter intuitive but unfortunately the way it works. If you are working with SharePoint 2010 the best way is to create the content type, deploy it and than add a list definition based on the content type. Visual Studio will generate the list definition for you and it will look like the above example. Are you re-creating the list each time after deploying changes to the list definition? –  Bernd Rickenberg Sep 14 '11 at 9:19
    
The way I developed back then when I wrote this question made it hard for this method to work, supposedly because each deployment wasn't made to a "clean" environment which left much old and similar content that messed up the new content. This is why It did not help me back then, but I think the method described in your answer would have worked. –  Tim Sep 17 '12 at 8:12
add comment

I typically use the ContentTypeBinding Element, then progammatically re-order the content types such that my 'bound' one is the new default.

share|improve this answer
    
I've used this method and found it very reliable. When I read it here from your description I did not understand it completely but once I read through the SharePoint Guidance material and reviewed the source code I finally got it, because they use this method there to. –  Tim Sep 17 '12 at 8:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.