Create a Custom SharePoint List Definition

By:   |   Comments   |   Related: > SharePoint


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:

start page

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.

new project

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

customization wizard

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

new item

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

online templates

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":

custom list

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

solution explorer

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.

schema

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

field names
  • "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:
process editor
create guid

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:

basic view

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

view fields

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:

solution explorer
output

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":

site actions

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

follow us

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

custom title

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:

new item

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

Next Steps


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Hesham Saad Hesham Saad

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips



Comments For This Article

















get free sql tips
agree to terms