Freigeben über


Creating List definitions with content types

When creating a couple of List Definitions which should be tied up to specific content types I came across a few issues on how to do this.

My scenario: I needed to create a External References Links list definition (not the same as the wss links list, but similar). I created a content type with the fields URL, Category and Description. Then I created a List Definition which is used to create a list that is bounded to the content type. Also, I needed to hide the Title field which is automatically created from the base content type (Item).

The end result is a list using the content type and it's fields like this screen dump shows an example of:

image

First of all,you need to create a Feature with the list definition (skipping feature creation details here):

image

TIP: If you need to create multiple list definitions in one feature you MUST use unique Type ID for each list definition (Type="10002" as shown above). If you only have one List definition, you can use "100".

 

Second, you need a schema.xml (and the form pages) file to define the list:

image

You should copy these files from existing lists and modify those. To connect the content type to the list you add the correct content type ID to the ContentTypeRef element in schema.xml like shown here:

image

Next, in the <Fields> element, you should put the fields you need in your list (from the content type). What you need to do is to add the exact same <Field> elements to the <Fields> element as in the content type, including the same ID. This is a little strange, but in fact you need to define the fields twice, both in the content type and in the schema.xml to make this work. You can skip the Group and a few other properties.

 

image

If you don't add the fields with the same <Field> element ID, you end up with regular columns in the list and not the ones defined in the content type.

The reason for adding the Title field which is derived from Item is that I need to hide this field.

Next,  add the same fields as <FieldRef> elements for each view in the schema.xml file:

image

(Since the Title field is gone, I added an Edit button to be able to edit the items in the list)

Now, even if I set the Title field to be hidden and not required, it still shows up in the New/Edit forms, so to hide them from the forms as well, you need to add the following properties to the <Field> elements of the content type:

ShowInEditForm="FALSE" ShowInNewForm="FALSE" ShowInDisplayForm="FALSE". Example:

image

Regards, Tommy Ovesen

Comments