Learn more about SQL Server tools

mssqltips logo
 

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Whitepapers          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories

 
Best Practices for Migrating SQL Server to Azure - free webinar
 

Create a Custom SharePoint List Definition


By:   |   Last Updated: 2011-09-22   |   Comments   |   Related Tips: > 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


Last Updated: 2011-09-22


next webcast button


next tip button



About the author





Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Email me updates 


Signup for our newsletter
 I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.



    



Learn more about SQL Server tools