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. hi,
    when we want to create a instance of list we need to create instance.xml file with some information. and we can insert some default data using instance.xml now when we activate Feature it will create new instance and insert the default data into list.
    you know any thing about this if the i have a problem

    Rakesh

    14 Apr 09 at 6:46 am

  2. I have done this tutorial 2 times now but i cannot see the "Submission" list when i go to the create-page. Can someone help?

    pieter

    5 Mar 09 at 2:17 pm

  3. Hi,
    Thanks for a great tutorial.
    When I create a new list,and then add a new item to it and click the "OK" button,I am redirected to the webpage having the error:
    "Server Error in '/' Application.
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.Runtime.InteropServices.COMException:Object reference not set to an instance of an object."
    Kindly help.

    Gautam

    5 Mar 09 at 8:30 am

  4. Thanks!

    Srikanth

    20 Feb 09 at 1:10 pm

  5. Thanks for publishing this; it was exactly what I was looking for.

    Brad

    19 Feb 09 at 9:56 pm

  6. Great work

    KH

    21 Jan 09 at 3:08 pm

  7. Ed – have you added the FieldRefs to both of the ViewFields elements? There are a couple of views so if you make sure to add it to both that should work.

    Ari Bakker

    15 Jan 09 at 11:29 pm

  8. This all seems to work, except I can't get the custom fields to display on the default view (AllItems.aspx). I made sure to add my custom fields as <FieldRef>s under <ViewFields> for the view.

    Ed.

    15 Jan 09 at 8:23 pm

  9. Where to add the fields and ViewFields in step 6 and 7. Are they added to the file in step 5.

    John

    20 Dec 08 at 7:06 pm

  10. Hi,
    I Followed the steps given you. I am able to find the custom list but when i create new item Except Title (default) no other columns appears.Am i missing anythng??Pls sort me

    Jasmine

    16 Dec 08 at 7:47 pm

  11. Hi,
    I have created custom colunm Lookup field.
    Now I need to filter on the behalf of selected Lookup values in the another dropdown lookup. How can i do?

    This help will be great appriciated

    Haque

    Anwarul

    3 Dec 08 at 2:12 pm

  12. Solved my previous problem, I had the name in my ConfigListElements different to the folder name that contained my schema, I also had a few typos.

    Have you got any example like the above for creating a custom Document Library with Content Types?

    Paul Matthews

    19 Nov 08 at 5:06 pm

  13. I've followed your code to the letter and I got it to work.
    I since have tried to replace your code with my own content type and list. I keep getting the error message
    Exception from HRESULT: 0x81070201 at Microsoft.SharePoint.Library.SPRequestInternalClass.CreateListFromFormPost(String bstrUrl, String& pbstrGuid, String& pbstrNextUrl)
    at Microsoft.SharePoint.Library.SPRequest.CreateListFromFormPost(String bstrUrl, String& pbstrGuid, String& pbstrNextUrl)

    Would you mind me emailing you my small demo, and see if you can see why I keep getting an error? It is almost a duplicate of your code, but using different content types.

    Paul Matthews

    18 Nov 08 at 5:22 pm

  14. Hi, I am trying to retrieve the items in my SharePoint list that have some Attachment to them. For this, in GetListItems(), i want to pass a query which says "finds its where Attachments is not equal to 0" The syntax I am using for it is: query.innerXml="0" But this is not working for me. Could anyone please tell me the correct syntax for this query.

    kreditrechner

    1 Nov 08 at 8:24 am

  15. … that was meant to say the 'ContentTypes' tags at the start of the file. The submission removed the tag

    Andy

    30 Oct 08 at 3:35 pm

  16. Hi
    I have set up a custom list containing a custom field type column and deployed with a feature in a wsp solution without setting up a custom column or content type outside of the list. This deploys fine and the newform.aspx and editform.aspx both show all the custom fields and behave correctly.
    All I did was use the schema from customlist, remove all the code within the <contenttype> tags at the start and then add the custom fields as new field tags.
    It seems to do the job easily and efficiently…
    Andy

    Andy

    30 Oct 08 at 3:28 pm

  17. Thank you!

    Dan

    15 Oct 08 at 8:19 pm

  18. @Anita and @JHenao – Martin Hatch has an article on <a href="http://mkeeper.spaces.live.com/blog/cns!60F12A60288E5607!278.entry">Custom Fields in the schema.xml</a> that describes the issue with declaring fields both in the content type and the list schema file, and provides a workaround that will automatically update the list with the fields from the content type.

    Ari Bakker

    14 Oct 08 at 9:18 am

  19. Thank You so much for such important information

    MoYa

    9 Oct 08 at 9:32 am

  20. @Michael – I agree it isn't a simple process, but copying the custom list definition (see step 4) and modifying the relevant places makes it a lot easier. I haven't included the entire schema file including the view elements as the schema file is over 2000 lines long, and we are only modifying a small section of this. I've mentioned the parts that need modifying and have used this successfully several times so if you are still having problems please include some details so we can work out what is happening here.

    Ari Bakker

    8 Oct 08 at 4:03 am

  21. I had a doubt. How can we apply edit control block for a particular column?? I searched on net but I couldnt get any thing. Can any body help me. As per Jason we can edit the item by creating view and providing LinkTitle column but the main drawback with this is you can not get versioning of that item.

    vishal jadhao

    6 Oct 08 at 9:58 am

  22. Your article talks about updating the view fields… Very nice, except you're missing a huge chunk in the views->views element. there is no mention of this in your article, You're presenting the subject as if its that simple, but its not…. in fact your code above just simply does not work…

    Michael

    3 Oct 08 at 6:49 am

  23. The reason for declaring the columns twice is due to pre-populating the list with data. As for the items becoming available within the default DispForm.aspx, EditForm.aspx and NewForm.aspx, I'm almost positive it is adjusted in the schema.xml file. I don't remember though so I'm checking it out and I'll post my findings.
    P.S. Thanks for the walkthrough.

    Zac Boyles

    21 Sep 08 at 6:05 pm

  24. Thank you for a concise and very readable walkthrough.

    rrkaushik

    16 Sep 08 at 9:24 pm

  25. I'd also like to know why this is the case. It seems that even though I've defined a content type for my custom list, the only way to change the data schema is to change the list schema.xml file, which is counter intuitive. You would think the list would be bound to the content type, but this doesn't seem to be the case. So I bind a list definition to a content type, redefine all the fields in the list schema.xml file, and now have no way of updating my list through the content type on which it was defined? Makes a ton of sense. This makes SharePoint lists extremely unusuable for data storage…i basically have no good way to update my model and maintain source control over it. Having these dependencies on different xml files and then not enforcing these dependencies is not a good practice at all.

    Rob

    14 Jul 08 at 6:06 pm

  26. I have this same questiion:

    "Why do the fields have to be defined in the custom site columns AND in the schema.xml file? The schema.xml file already has references to the fields through the contenttypes definition (with field references). Please explain this to me!"

    this seems to have no sense…one reason to create a content type and site columns feature precisely becouse is a good practice maintenance and upgrade…

    I would appreciate a clarification

    JHenao

    5 Jun 08 at 11:32 pm

  27. Hey,
    Ive created my own Editform.aspx and NewForm.aspx and put it inside the layouts folder, Is it possible to use these pages for my custom list instead of those ghosted forms? Also, is there a way to include a dataview webpart in the Viewall and dispform.aspx and deploy it as a part of definition? Currently, i can only deploy these pages manually using SP Designer.. Any advice?

    Anton Evasco

    28 May 08 at 6:58 am

  28. Draxtor, to make the item editable, are you sure you have this in your ViewFields?

    <FieldRef Name="LinkTitle">
    </FieldRef>

    I had Name="Title". I couldn't edit from AllItems

    Jason

    22 May 08 at 12:36 am

  29. Wow! Finally, here is an example that works!
    Thank you for posting this!

    I'm so grateful!

    =)

    Leing

    8 May 08 at 4:27 pm

  30. It all works. but my list is not editable. I can edit it in datasheet view, but I can not click on title to edit it

    Draxtor

    9 Apr 08 at 11:51 am

  31. Now we have created our own "Custom List"

    Anyone please tell me how do I add this list automatically in a site creation.

    I have made my own sitetemplate/definition
    What/where shall I modify in the "onet.xml" file.

    http://www.heathersolomon.com/blog/articles/1300.aspx

    I did try to read the above guide "Step 4".. but that is for 2003… many things have been modified in 2007 seems to be.

    Anybody please help me.

    Suresh

    2 Apr 08 at 6:19 am

  32. The bewildering jungle of XML required to do things like this just begs for a more visual, drag-and-drop type of development tool that would take care of such things as duplicating field definitions between the various files and any other non-intuitive steps needed to create a custom list. The guy/gal who creates such a tool will be rich beyond their wildest dreams 🙂

    Fred

    25 Jan 08 at 5:08 pm

  33. Thanks for the guide – everything work for me except the fields I add to the list don't appear in the create form.
    Any ideas why this might be?

    Thanks

    Tim

    Tim

    24 Jan 08 at 2:10 pm

  34. Awesome Article Ari!!

    shane perran

    2 Nov 07 at 2:27 pm

  35. Why do the fields have to be defined in the custom site columns AND in the schema.xml file?
    The schema.xml file already has references to the fields through the contenttypes definition (with field references).
    Please explain this to me!

    Anita

    29 Oct 07 at 8:29 am

  36. Is there any way to create List definition with out using the site columns… What i mean is can we include our own columns(which is specific to list) in Schema.xml. I tried it, but didn't get the columns in instance of the list.

    Muralidharan P

    23 Oct 07 at 8:44 am

  37. If you get this error: Exception from HRESULT: 0x81070201 on trying to create a new Submissions List then you need to move the Submissions folder containing the schema.xml into the root of the SubmissionList folder, instead of in the ListTemplate folder. This bug got me, and was a pain to figure out. You can see an explanation here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2019155&SiteID=1

    Thanks

    12 Oct 07 at 8:04 pm

  38. Great and useful step by step article!
    Thank you very much!

    Alex B.

    9 Oct 07 at 1:12 pm

  39. Do you know if it's possible to adding formatting to one of the .xml files to change the way the list is displayed in the NewForm.aspx and EditForm.aspx files? What .xml file would you edit?

    Tobias

    27 Sep 07 at 4:45 am

  40. thanks for the step by step guide. i done all the steps mentioned in your article. couldn't find the submissions custom list in the custome list tab under operations. pls help me what to do. thanks in advance

    pradeep

    25 Aug 09 at 5:56 am

  41. This article is a dummies guide. Thank you!

    Tukaram Thatikonda

    23 Jun 09 at 2:13 am

  42. Thank you!

  43. good article. helped me alot

    leo

    5 May 09 at 11:01 pm

  44. Thanks Ari, very nice article saving me a lot of digging. Worked just fine 🙂

    Temruk

    16 Dec 09 at 4:02 pm

  45. Thanks for the guide – everything work for me except the fields I add to the list don’t appear in the create form. Any ideas why this might be? Thanks Tim

    kiran

    3 Mar 10 at 6:43 am

  46. @kiran – do the fields show in the site columns and site content type galleries (from site actions > site settings) and have you done an iisreset after deployment?

    Ari Bakker

    4 Mar 10 at 5:38 pm

  47. Yes, i have restarted my iis. I have removed the ContentTypes element altogether then its working.thanks!

    kiran

    4 Mar 10 at 11:09 pm

  48. I have done this tutorial, now but i cannot see the “Submission” list when i go to Site Settings > Site Features. Please help me.

    kiran

    4 Mar 10 at 11:41 pm

  49. Please ignore my previous comment.
    Everything work for me except the fields I add to the list don’t appear in the create form.
    I have removed the ContentTypes element altogether in Schema.xml file then its working.
    Any ideas why this might be?

    Thanks,
    Kiran

    kiran

    5 Mar 10 at 1:24 am

  50. I did this tutorial.However I didn’t see Submissions in my custom lists section. Can you please let me know what went wrong?

    Thanks.

    sspb4

    23 Jun 10 at 11:12 am

  51. @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

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

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

*