Export (0) Print
Expand All
8 out of 17 rated this helpful - Rate this topic

Create Custom List Definitions in SharePoint 2010

SharePoint 2010

SharePoint QuickStart Banner

Getting Started with Web Development in SharePoint 2010:  Learn how to create a custom list definition in SharePoint 2010 and then attach an event receiver to it.

Applies to:  Microsoft SharePoint Foundation 2010 | Microsoft SharePoint Server 2010 | Microsoft Visual Studio 2010

Published:  June 2010

Provided by:   Frank Rice, Microsoft Corporation

In this exercise, you create a custom list definition in Microsoft SharePoint 2010 and then create an event receiver that is triggered when the list is used. To complete this task, you must do the following:

Create a SharePoint List Definition Project

In this task, you create a list definition SharePoint 2010 project in Microsoft Visual Studio 2010.

To create the SharePoint project

  1. To start Visual Studio 2010, click the Start Menu, click All Programs, click Microsoft Visual Studio 2010, and then click Microsoft Visual Studio 2010.

  2. On the File menu, point to New, and then click Project.

  3. In the New Project dialog window, in the Installed Templates section, click Visual C#, click SharePoint, and then click 2010.

  4. Click List Definition from the project items.

  5. In the Name box, type Bugs and then click OK.

  6. In the SharePoint Customization Wizard, type the local Web site that you want to use for this exercise (such as http://localhost/SampleWebSite).

  7. For the trust level, select Deploy as a farm solution and then click Next.

  8. In the What is the display name of the list definition? Box, type Bugs.

  9. In the What is the type of the list definition? drop-down list, select Custom List.

  10. Select the Add a list instance for this list definition check box and then click Finish.

Customize the SharePoint List Definition

This task guides you through customizing the List Definition project template by changing the list name, the content type it stores, and the fields that are displayed in the new form, edit form, and display form.

To customize the list definition

  1. In Solution Explorer, expand ListInstance1 and open the Elements.xml file.

  2. Within the ListInstance element change the Title attribute to Bugs and change the TemplateType attribute to 10001.

  3. In Solution Explorer, before Schema.xml, open Elements.xml.

  4. Within the ListTemplate element, change the Type attribute to 10001 and add the DisallowContentTypes=”FALSE” attribute.

  5. Insert the following XML into the top of the Elements element in the Elements.xml file as shown in Figure 1. This XML describes the Bug Item content type the list stores.

    <!-- Describes content types. -->
    <ContentType
      ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94"
      Name="Bug Item"
      Group="Custom Content Types"
      Description="Bug item content type."
      Version="0">
      <FieldRefs>
        <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" />
        <FieldRef ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" />
        <FieldRef ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}" />
        <FieldRef ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}" />
      </FieldRefs>
    </ContentType>
    <!--  End describes content types. --> 
    
  6. Insert the following XML into the top of the Elements element in the Elements.xml file as shown in Figure 1. This XML describes the fields the Bug Item content type uses.

    <!-- Describes fields in bug list. -->
    <Field Type="Note" DisplayName="Description" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="BugDescription" Name="BugDescription" Group="Custom Columns" />
    <Field Type="Text" DisplayName="Project" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}" StaticName="BugProject" Name="BugProject" Group="Custom Columns" />
    <Field Type="Text" DisplayName="Assigned To" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}" StaticName="BugAssignedTo" Name="BugAssignedTo" Group="Custom Columns" />
    <!-- End describes fields in bug list. -->
    

    Figure 1. Elements.xml file after inserting two code sections

    Elements.xml file after inserting code
  7. In Solution Explorer, open Schema.xml.

  8. Add the EnableContentTypes=”TRUE” attribute to the List element inside the Schema.xml file.

  9. Insert the following XML into the ContentTypes element in the schema.xml file as shown in Figure 2. This XML describes the Bug Item content type this list stores.

    <!-- Start Add. -->
    <ContentTypeRef ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94" />
    <!-- End Add. -->
    
    
  10. Insert the following XML into the Fields element as shown in Figure 2. This XML describes the fields the list stores. These are directly related to the fields in the content type that you added in the previous step.

    <!-- Start Add. -->
    <Field Type="Note" DisplayName="Description" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="BugDescription" Name="BugDescription" Group="Custom Columns" />
    <Field Type="Text" DisplayName="Project" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}" StaticName="BugProject" Name="BugProject" Group="Custom Columns" />
    <Field Type="Text" DisplayName="Assigned To" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}" StaticName="BugAssignedTo" Name="BugAssignedTo" -Group="Custom Columns" />
    <!-- End Add. -->
    

    Figure 2. Schema.xml after inserting the ContentTypeRefs code and Fields code

    Schema.xml after inserting ContentTypeRefs
  11. Insert the following XML into the ViewFields element in the second view, where BaseViewID="1" as shown in Figure 3. This XML describes which fields should be visible in this particular view. BaseView 1 is set as the default view. This is the view the newly created fields should display in.

    <!-- Start Add. -->
    <FieldRef Name="BugDescription"></FieldRef>
    <FieldRef Name="BugProject"></FieldRef>
    <FieldRef Name="BugAssignedTo"></FieldRef>
    <!-- End Add. -->
    

    Figure 3. Schema.xml after Fields XML insert

    Schema.xml after inserting Fields XML
  12. In Solution Explorer, right-click the Bugs node, and then click Deploy.

Test the Solution

In this task, you test the solution by adding a bug to the Bugs list.

To add an item to the Bugs list

  1. Open the website that you specified previously.

  2. On the Home page, click the Bugs list in the left navigation pane.

  3. On the List Tools tab, click Items, and then click Bug Item on the New Item drop-down list as shown in Figure 4.

    Figure 4. Bug Item from the New Item drop-down list

    Bug Item from the New Item list

    The Bugs - New Item screen is displayed as shown in Figure 5.

    Figure 5. New Bug Item dialog box

    New Bug Item dialog box
  4. In the Bugs - New Item screen, type Bug01 in the Title box.

  5. Type Who is going to track this bug? in the Description box, type Writing developer articles in the Project box, and then click Save.

Next Steps

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.