Subscribe:      
 

Create a Custom SharePoint List Definition

Written By: Hesham Saad -- 9/22/2011 -- join -- contribute -- (6) comments -- printer friendly version

Rating: Rate --

Categories: Design, Programming and Customizations, SharePoint 2010, SharePoint Foundation 2010

Problem

Creating an "Out of the box" predefined SharePoint list is easy but limited. How about creating a custom list via Visual Studio.Net 2010 and adding custom list fields with different data types?

Solution

Microsoft Visual Studio 2010 provides a project type that makes it easier to create list definitions in XML and to create list instances that are based on those definitions. A field definition, defines the columns that appear inside of the list template. For more information about the XML that is used to define a field type, see Field Types XML. Let's follow the steps below to create custom list fields with different data types at a SharePoint custom list definition...

Open Visual Studio.Net 2010 -> File (Menu) -> New -> Project:

1


Select "2010" for SharePoint under "Installed Templates" from the left side panel -> Select "Empty SharePoint Project" from the right side panel. Type a name for your project, then click the OK button.

2

Type the URL of your local SharePoint site at the "What local site do you want to use for debugging?" textbox and choose "Deploy as a farm solution" (Read about the differences between Farm & Sandbox Solutions):

3

Click on the "View" menu -> Solution Explorer -> right-click at the created solution -> Add -> New Item:

4

Select "2010" for SharePoint under "Installed Templates" from the left side panel. -> Select "List Definition" from the right side panel:

5

Keep/Edit the display name of the list definition. Select "Custom List" as the type of the list definition and check "Add a list instance for this list definition":

6

Here is our solution with the created custom list definition and added list instance:

            7

Let's add some custom list fields with different data types. Open the "Schema.xml" file under created the "customListDefinition" directory. Select the "ContentTypes" tag section under "MetaData" and remove it. (We don't need for now in this tip to create the custom content type and associate it to our custom list definition.

7.1

Then add the fields below under the "Fields" tag section:

7.2

 "Type = Text" : Single line of text. (Plain Text).

"Type = Note" : Multiple line of text.

"Type = Image" : Publishing rollup image. (Image Picker).

"Type = URL" : Hyperlink (with URL and description fields).

"Type = Boolean" : Check Box.

"Hidden = TRUE" : In order to hide the default created column "Title" field for any custom list.

"ID" : Identifier value representing a GUID "Global Unique Identifier" which can be uniquely created as follows:

7.3  

 7.4

Then, let's show the above created fields at the listing view "AllItems". Search for the "View" tag where "DefaultView=TRUE" in the "Schema.xml" file:

7.5

 

In the "ViewFields" tag section, add the "FieldRef" fields below, then save all:

7.6

Right click on the "ListDefViaVS2010" project, then select "Deploy"  in order to deploy our solution to the SharePoint site. Then wait until we check that the output is successfully deployed:

8

 

9

Now let's go to the SharePoint site to check the deployed custom list definition. Click the "Site Actions" menu then "View All Site Content":

10

As we can see below a new added list instance to our custom list definition "ListDefViaVs2010 - ListInstance1" :

11

Click on "ListDefViaVS2010 - ListInstance1" to go to the listing view "AllItems" form:

12

We can see all defined "FieldRef" fields under "ViewFields" tag section at "Schema.xml" list definition file.

Then , Let's click on the "Add new item" link:

13

Now we can see all defined custom fields under the "Fields" tag section in the "Schema.xml" list definition file.

 

Next Steps




Learn more about SharePoint



Sponsor Information




Copyright (c) 2010-2017 Edgewood Solutions, LLC All rights reserved
privacy | disclaimer | copyright | advertise | contribute | feedback | about
Some names and products listed are the registered trademarks of their respective owners.


MSSharePointTips.com | MSSQLTips.com