Monday, December 17, 2007

List Template Types

We have been discussing various parts of features and solutions and how you can use them to efficiently build your SharePoint business solution. One of the most basic things is to create a list template that instances can base themselves on. To begin your list template feature you need to create a ListTemplate element. This element has many attributes that define your list. One of the most important of these is the Type attribute. In the MSDN documentation it states that this is

"Optional Integer. Provides a unique identifier for the template. This identifier must be unique within the feature, but need not be unique across all feature definitions and site definitions. It then lists the built in template types and the type of list that they correspond to:

100 - Custom List
101 - Document Library
102 - Survey
103 - Links List
104 - Announcements List
105 - Contacts List
106 - Events List
107 - Tasks List
108 - Discussion Board
109 - Picture Library
110 - Data Sources
111 - Site Template Gallery
113 - Web Part Gallery
114 - List Template Gallery
115 - XML Form Library
120 - Custom Grid for a list
200 - Meeting Series List
201 - Meeting Agenda List
202 - Meeting Attendees List
204 - Meeting Decisions List
207 - Meeting Objectives List
210 - Meeting Text box
211 - Meeting things to bring list
212 - Meeting Workspace Pages List
300 - Portal sites list
1100 - Issue Tracking
2002 - Personal Document Library
2003 - Private Document Library

It then states that this value corresponds to the Type attribute of the List element.

We have been having some problems with this actually working, though. We built out some lists using the Visual Studio extensions for WSS and we wanted to place some list event receivers on a specific list. Well according to the extensions you should be able to do this by adding the event receivers to the .cs files for that list instance. We tried that and the event receivers were on every custom list. So we poked into the XML for the list instances and found that all of them were using type 100 or (Custom list). So we tried changing them to a different numbers in the 800 range, such as 800, 801, 802, etc. When we tried to deploy the new solution and check the list we received an HRESULT error, which most people know are some of the most unhelpful errors you can get in SharePoint. So we changed the numbers back and then re-deployed and the lists worked fine again.

The documentation says that it needs to be a unique integer across the feature. All of ours were and yet they did not work. If anyone has more insight as to how these list templates really work, feel free to leave a comment explaining them.

Labels: , , ,

Wednesday, April 18, 2007

A List Template of Your Very Own

To create your own list template using a feature is pretty easy. The only difficult part is trying to understand the documentation on the MSDN about which attributes are required and which are optional. When it comes to my experience with features and list templates, I have found that all of the attributes should be required, otherwise Sharepoint will place something in there for you and in our case this destroyed the out of the box templates on our Sharepoint site.

The first step is to create the Feature.xml file with a name for your feature and the location of the Elements.xml file.

<feature title="Simple List Feature" id="GUID" scope="Web" xmlns="http://schemas.microsoft.com/sharepoint/">
<elementmanifests>
<elementmanifest location="Elements.xml">
</elementmanifests>
</feature>

After that you can create the Elements.xml file and place the ListTemplate node in there.

<elements>
<listtemplate name="SimpleList" displayname="Simple List" type="20" description="This is my simple list." basetype="0" onquicklaunch="FALSE" securitybits="11">
</elements>

The ListTemplate tag is pretty simple. You give it a name and a display name. The display name shows up in the site settings area for list templates. The description field is used to provide more information about your list template. The basetype is the default schema for the lists created from this template. Most times this will be 0. The onquicklaunch allows the list template to show up on the quick launch bar. The security bits allows for read, write, and schema design security.

There are many other fields that you can use in the list template to customize it the way you want. The resource below lists all of these fields.

<edit>
It has been brought to my attention that I forgot to mention the schema.xml file. At the time that this post was originally written, we copied a schema.xml file from an existing list and then modified it. Microsoft recommends this approach as building the schema file from hand is time consuming and very prone to errors. There are also tools out there that will generate schema files from a list that you build using the UI.
</edit>

http://msdn2.microsoft.com/en-us/library/ms462947.aspx

Labels: , , , ,