1. Create custom site columns (Optional)
2. Create custom content types (Optional)
3. Create custom list definition
The trick is to make sure that the list definition is based on a content type that contains all the site columns required in the list definition (or the columns will not show up in the ‘add new item’ form).
So the first two steps can be avoided if your list definition is based on existing site columns and content types.
The following example will create a custom ‘TechComment’ list definition that could be used for accepting Technical Comments on a particular technical issue.
To do this a custom site column that will hold the Technical comments is created.
This and several existing site columns are used to create a custom ‘TechComment’ content type. The TechComment list definition is then created based on this content type.
Each item is deployed as a separate feature in this example.
Creating a custom site column for the TechComment comments
1. Create a folder named TechCommentColumns in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES (FEATURES) directory.
2. Create an xml file named feature.xml inside this folder that contains the following information:
3. Create a xml file named TechCommentcolumn.xml that contains the following information:
Here we are defining the system name (Name and StaticName) the base type (Type) and several other attributes of our site column.
The FEATURES\fields folder contains examples of default site columns, and is useful in understanding how all these attributes are used.
4. Activate the feature using the following commands
(in a command window, from the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN directory):stsadm -o installfeature -filename TechCommentColumns\feature.xml -force
stsadm -o activatefeature -filename TechCommentColumns\feature.xml -url http://localhost/
Creating a custom ‘TechComment’ content type
1. Create a folder named TechCommentCT in the FEATURES directory.
2. Create a xml file named feature.xml that contains the following information:
3. Create a xml file named TechCommentct.xml that contains the following information:
The FEATURES\ctypes folder can be used to find the ID’s of system content types we might want to use as a base.
You should also check that the ID of your new content type is unique.
Another important point to note is that the FieldRef ID's must match ID's for existing site columns.
We can see that the ID of the TechCommentComment field matches that of the site column we defined in step 1 by looking at the elements xml file we used to define the column.
To find out the ID of other fields we want to use you can look in the FEATURES\fields folder to see a list of all the default field/column types.
4. Activate the feature using the following commands:
stsadm -o installfeature -filename TechCommentCT\feature.xml -forcestsadm -o
activatefeature -filename TechCommentCT\feature.xml -url http://localhost/
Creating a custom TechComment list definition
1. Create a folder named TechCommentsList in the FEATURES directory.
2. Create a xml file named feature.xml that contains the following
3. Create a folder named ListTemplate inside the TechCommentsList folder and add an xml file named TechComments.xml that contains the following
4. Create a folder named TechComments inside the TechCommentsList folder and copy the FEATURES\CustomList\CustList\Schema.xml file into the TechComments folder.
5. Update the ContentTypes element in the Schema.xml file to the following:
Here we define our custom ‘TechComment’ content type as the base type for this list.The columns defined in this content type are then shown on the ‘add new item’ page.
6. Update the Fields element in the Schema.xml file to the following:
7. Lastly update the ViewFields element to contain the columns we want to display on our default list view:
8. Activate the feature using the following commands:stsadm -o installfeature -filename TechCommentList\feature.xml -forcestsadm -o activatefeature -filename
TechCommentList\feature.xml -url http://localhost/iisreset
You should now be able to create a new instance of the TechComments list from the create list page as shown below:
Some points to note are that the ID's for features and fields you create need to have new GUID's generated for them. When including fields in content types or list definitions the GUID/ID must match the GUID of the list (you can look in the feature folder for the field to find this out).