SharePoint: Create List Template/ List definition - Part 1

Glad to pull this up after so much difficulties...url blocked in office, no internet/development environment at home and work sufficient enough to keep me busy in weekends also.

Coming to the actual topic, List template is definition or schema of the list where
fields, content types, views and forms can be specified. It is used to create
multiple lists of same type or structure. We will see how easy it is to create the list definitions step by step.

4.Rename
the Feature 1 folder to List Templates as shown in Figure 3 for
better readability.

Figure 3: Rename the Feature folder

5.In
Solution Explorer, right-click the SPCustomDevelopment
project, select Add, and then
select New Item as shown in Figure 4.
Type the name as BookList Template

Figure 4: Add List Definition project item

6.In
the next window, make the changes as shown in figure 5 and click Finish button.

Figure 5: List Template wizard

This will create two files,
elements.xml and schema.xml. In addition VS 2010 will also associate the newly
added Book List Template item to List Templates feature as element
manifest.

The elements.xml contains list template defined using ListTemplate tag. The content types,
site columns, list forms and list views to be associated with list template is
defined in scehma.xml as shown in figure.

Figure 6: List Schema structure

7.In
schema.xml remove the Item and Folder content type references and add Book
content type in the ContentTypes tag
as shown in Figure 7. Note that multiple content types can be associated with
single content type. (copy the content type definition from schema given in
step no 9)

Figure 7: Copy content types into the
schema

Note that instead of
mentioning all the content type definition, only reference to content types
also can be mentioned in the schema.xml using ContentTypeRef tag.

8.Add
site columns definitions into the Fields
tag as shown in Figure 8. (copy the
field definitions from schema given in step no 9)

Figure 8: Add site columns into the schema

9.Name
the view having BaseViewID equal to
1 as All Books and change its ViewFields as shown in figure 9.

Figure 9: Create a List View

Note that the other view
operations like grouping, filtering the items can also be defined in the view
definition of schema in Query tag.

11.Once
deployment is successful, Book List
Template will be created as shown in figure 11. It can be used to create
multiple lists of type Book List
Template having same structure.

Figure 11: Newly Added Book List
Template

One important thing to
remember here is, fields and content types in schema.xml are list fields and
list content types.You can create list fields and list content types without creating site fields and site content types.

Custom list forms

There are various ways to modify the list forms. Few are
mentioned in my last blog Basicsof Content Types where forms are associated with content types instead of
list directly. List schema (schema.xml) too provide a way to associate custom list forms
through Forms tag which once
associated, are used for all list content types.

I am not going into details how to associate the custom list
forms to list using Forms tag. It is
best explained by Igno Karstein
his two blogs with examples.

Even though I personally like creating list definitions
using above traditional approach as I believe it helps me to understand/learn
the list definitions, fields and content types all together in better way. There is another
approach to create list definition using which you can generate the list
definition schema. It does not require knowledge of field, content type
schemas. Will cover that in my next blog in this series.