Create a Custom SharePoint List Definition
Written By: Hesham Saad -- 9/22/2011 --
(6) comments --
Categories: Design, Programming and Customizations, SharePoint 2010, SharePoint Foundation 2010
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?
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
Types XML. Let's follow the steps below to create custom
list fields with different data types at a SharePoint custom list
Open Visual Studio.Net 2010 -> File (Menu) -> New -> Project:
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.
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
Farm & Sandbox Solutions):
Click on the "View" menu -> Solution Explorer ->
right-click at the created solution -> Add -> New Item:
Select "2010" for SharePoint under "Installed
Templates" from the left side panel. -> Select "List Definition" from the
right side panel:
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":
Here is our solution with the created
custom list definition and added list instance:
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
type and associate it to our custom list definition.
Then add the fields below under the "Fields" tag section:
= 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
"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
created as follows:
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:
In the "ViewFields"
tag section, add the "FieldRef" fields below, then save all:
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:
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":
As we can see below a new added list instance to our
custom list definition "ListDefViaVs2010 - ListInstance1" :
Click on "ListDefViaVS2010 - ListInstance1" to
go to the listing view "AllItems" form:
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:
Now we can see all defined custom fields under the
"Fields" tag section in the "Schema.xml" list definition file.