Creating Custom List Definitions

You have created a list and a library using out of the box list templates. At times you will want to define your own list template and create a list using that. It’s easy to create a new list template using Visual Studio. This section shows the process of creating a new list definition.

Open the CustomSchema project created earlier. Select List Definition from Content Type and name it Product List. Click the Add button. You are shown the Choose List Definition Settings as shown in Figure 10.12.

Image

Figure 10.12. Choose List Definitions Settings screen

Change the display name to Product List. Select the Product content type and check the Add a List Instance for This List Definition box. Click Finish. You see two elements.xml files created and a schema.xml created as shown in Figure 10.13.

Image

Figure 10.13. Visual Studio 2010 project structure for Product List

Open the Schema.xml file and the Elements.xml directly under the Product List folder. You can see the list definition XML. The schema.xml specifies the content types used by the list; the views; the new, edit, and display forms; and a lot of other information. The elements.xml file specifies the list template information such as the name, display name, description, template type (this is a unique number that will be used by the list instances), and base type.

Open the elements.xml file under the ListInstance1 folder. You can see that a new list instance is defined using your new list template. Note the TemplateType is the same as the type in the ListTemplate element.

Deploy the solution. Browse to the SharePoint site and you should see the new list in the Quick Launch menu. Also try to create a new list. You can see the new list template in the list of templates shown in Figure 10.14.

Image

Figure 10.14. The Product List template option in the Create New List screen

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset