SharePoint Config

Ari Bakker's thoughts on customising and configuring SharePoint

Creating a Custom SharePoint 2007 List Definition

with 53 comments

There are several steps involved in creating a custom list definition in SharePoint 2007. These are:

  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 ‘submission’ list definition that could be used for accepting submissions on a particular issue. To do this a custom site column that will hold the submission comments is created. This and several existing site columns are used to create a custom ‘submission’ content type. The submission 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 submission comments

1. Create a folder named SubmissionColumns 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:


<?xml version="1.0" encoding="utf-8" ?>
<Feature
Id="{a94f84a5-c87a-4fef-8e01-f064bc1bd9d7}"
Title="Submission Columns"
Description="This feature contains site columns used in the submission process"
Version="12.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="submissioncolumn.xml" />
</ElementManifests>
</Feature>

3. Create a xml file named submissioncolumn.xml that contains the following information:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Field ID="{374e02cc-fe2e-4247-8762-e69242f9ff94}"
Name="SubmissionComments"
SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="SubmissionComments"
Group="Submission Columns"
Type="Note"
DisplayName="Comments"
Sortable="FALSE"
Description="Comments on the submission"
Sealed="TRUE"
UnlimitedLengthInDocumentLibrary="TRUE"
AllowDeletion="TRUE"
ShowInFileDlg="FALSE">
</Field>
</Elements>

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 SubmissionColumns\feature.xml -force
stsadm -o activatefeature -filename SubmissionColumns\feature.xml -url http://localhost

Creating a custom ‘submission’ content type

1. Create a folder named SubmissionCT in the FEATURES directory.

2. Create a xml file named feature.xml that contains the following information:


<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="{56615608-9e3d-4ff6-b2c6-90e070e45ff8}"
Title="Submission Content Types"
Description="This feature contains content types used in the submission process"
Version="12.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="submissionct.xml" />
</ElementManifests>
</Feature>

3. Create a xml file named submissionct.xml that contains the following information:


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType
ID="0x01AB"
Name="Submission"
Group="Submission Content Types"
Description="Create a new submission"
Version="0">
<FieldRefs>
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Title" Sealed="TRUE"/>
<FieldRef ID="{475c2610-c157-4b91-9e2d-6855031b3538}" Name="FullName" Required="TRUE" />
<FieldRef ID="{fce16b4c-fe53-4793-aaab-b4892e736d15}" Name="Email" Required="TRUE" />
<FieldRef ID="{374e02cc-fe2e-4247-8762-e69242f9ff94}" Name="SubmissionComment" Required="TRUE" />
</FieldRefs>
</ContentType>
</Elements>

Here we are defining basic attributes for our content type and the site columns that we will be using. One important piece of information is the ID attribute. This tells us that our content type is based on the content type with ID 0x01, the ‘Item’ content type. 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 SubmissionComment 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 SubmissionCT\feature.xml -force
stsadm -o activatefeature -filename SubmissionCT\feature.xml -url http://localhost

Creating a custom submission list definition

1. Create a folder named SubmissionsList in the FEATURES directory.

2. Create a xml file named feature.xml that contains the following information:


<?xml version="1.0" encoding="utf-8" ?>
<Feature
Id="{6d2c42db-782c-417e-9c7c-2c941ef52b92}"
Title="Submission List"
Description="This feature contains a submission list definition"
Version="12.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="ListTemplate\Submissions.xml" />
</ElementManifests>
</Feature>

3. Create a folder named ListTemplate inside the SubmissionsList folder and add an xml file named Submissions.xml that contains the following information:


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListTemplate
Name="Submissions"
Type="6500"
BaseType="0"
OnQuickLaunch="TRUE"
SecurityBits="11"
Sequence="360"
DisplayName="Submissions"
Description="Create a submissions list when you want to allow users to submit submissions on a document"
Image="/_layouts/images/itgen.gif" />
</Elements>

Here we are defining a unique type number for our list (which can be used if we want to include this list in a custom site definition), the sequence it should appear in the ‘create’ page and other basic attributes. Note the displayname used must match the folder that contains the list schema defined in the next step.

4. Create a folder named Submissions inside the SubmissionsList folder and copy the FEATURES\CustomList\CustList\Schema.xml file into the Submissions folder.

5. Update the ContentTypes element in the Schema.xml file to the following:


<ContentTypes>
<ContentTypeRef ID="0x01AB">
<Folder TargetName="Submission" />
</ContentTypeRef>
<ContentTypeRef ID="0x0120" />
</ContentTypes>

Here we define our custom ‘submission’ 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:


<Fields>
<Field
Name="Title"
ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}"
DisplayName="Title"
Sealed="TRUE"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="Title">
</Field>
<Field
ID="{475c2610-c157-4b91-9e2d-6855031b3538}"
Name="FullName"
DisplayName="$Resources:core,Full_Name;"
Type="Text"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="FullName">
</Field>
<Field
ID="{fce16b4c-fe53-4793-aaab-b4892e736d15}"
Name="Email"
DisplayName="$Resources:core,E-mail_Address;"
Type="Text"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="Email">
</Field>
<Field ID="{374e02cc-fe2e-4247-8762-e69242f9ff94}"
Name="SubmissionComments"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="SubmissionComments"
Group="Submission Columns"
Type="Note"
DisplayName="Comments"
Sortable="FALSE"
Description="Comments on the submission"
Sealed="TRUE"
UnlimitedLengthInDocumentLibrary="TRUE"
AllowDeletion="TRUE"
ShowInFileDlg="FALSE">
</Field>
</Fields>

Here we define the custom fields from our content type that we want to use in our list.

7. Lastly update the ViewFields element to contain the columns we want to display on our default list view:


<ViewFields>
<FieldRef Name="Attachments">
</FieldRef>
<FieldRef Name="LinkTitle">
</FieldRef>
<FieldRef Name="FullName">
</FieldRef>
<FieldRef Name="Email">
</FieldRef>
<FieldRef Name="SubmissionComments">
</FieldRef>
</ViewFields>

8. Activate the feature using the following commands:

stsadm -o installfeature -filename SubmissionList\feature.xml -force
stsadm -o activatefeature -filename SubmissionList\feature.xml -url http://localhost
iisreset

You should now be able to create a new instance of the submissions list from the create list page as shown below:

Creating a new submission list

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).

This post was based on an example given by Ton Stegeman, he also has some great articles on creating site columns and creating content types.

Post to Twitter Post to Delicious Post to Digg Post to Reddit Post to StumbleUpon

Written by Ari Bakker

April 17th, 2007 at 9:56 pm

53 Responses to 'Creating a Custom SharePoint 2007 List Definition'

Subscribe to comments with RSS or TrackBack to 'Creating a Custom SharePoint 2007 List Definition'.

  1. @sspb4 what version of SharePoint are you using, also did the site columns and content type show up?

    Ari Bakker

    14 Dec 10 at 6:22 pm

  2. Hi,
    When i run the command “stsadm -o installfeature -filename SubmissionList\feature.xml -force” in step 8 of step “Creating a custom submission list definition” I have got an error message “Failed to find the XML file at location ’12\Template\Features\submissionlist\feature.xml'”, please help me to solve this problem, thanks.

    Phu Dang

    Phu Dang

    18 Feb 11 at 7:57 am

  3. Hi Phu, have you checked the file it is referring to is there? By default the 12 folder is at C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ so the file should be in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\SubmissionList\ folder.

    Ari Bakker

    19 Feb 11 at 12:23 pm

Leave a Reply

*