How to Create a Custom Content Type and Custom List in SharePoint 2013

Dynamics 101 18 April 2013 0

In this post we will learn how to create custom site columns in SharePoint 2013. We will then use them to create a custom content type which we will eventually be used to create a custom list.

For users who have created custom content types/lists in SharePoint 2010 using Visual Studio 2010, things are a lot easier with Visual Studio 2012. We don’t need to manipulate any xml within the schema.xml or elements.xml files for most of our requirements.

Custom Site columns

In this section we will prepare two site columns.

  • Name – single line of text
  • Sex – choice (options : male and female)

We are assuming that we have a visual studio solution targeting SharePoint 2013 as the starting point.

  1. Right click on the visual studio solution and add a site column (it will be present under “office/SharePoint” collection). Let us name it “Name”. Using the elements.xml we can change a few attributes like “DisplayName”, “Required”, etc. For our example we will not need to make any changes here. We will keep the “Type” as Text, since the Name column is expected to be a single line of text.
  2. Similar to the above step we will add another site column and name it “Sex”. We will change the Type attribute of this column to “Choice”. We will then add the Choices as shown below.

We now have two custom site columns. We will now use them to create a custom content type “PersonalInfoCT”.

Custom content type

We will use the same SharePoint solution. Let us add a content type (found under “Office/SharePoint” group of items) by right clicking the visual studio solution. We will name it as “PersonalInfoCT”. As mentioned earlier, unlike the previous versions, Visual Studio 2012 gives a nice user interface to add content type without doing any xml changes.

After selecting the content type we will get the interface to select the base content type. For our purposes we will choose item content type. Please refer to the image below:

After choosing the base content type, we will get the option to choose site columns to add to our content type. For this example, we will add the two site columns “Name” and “Sex” to the content type “PersonalInfoCT”. We can set the columns as required by checking the required column beside them. Once this is complete we will have created the content type “PersonalInfoCT”.

Custom list using the custom content type created above

In this section we will create a custom list called “PersonalInfo” using the content type “PersonalInfoCT”. Similar to the previous sections we will add a list (found under “Office/SharePoint” group of items) to our solution.

We will use the friendly user interface to create our list.

The first step will be to add the content type “PersonalInfoCT” for list “PersonalInfo”. Then we need to select “PersonalInfoCT” as the default content type for our list by clicking on the “set as Default” button. Clicking OK will add our content type to the list and make our site columns available to the list “PersonalInfo”.

Deploying the project to a SharePoint site will make the list available to us. We have used the user interface provided by Visual Studio 2012 to create the content type and list. We can also do the same by modifying element.xml and schema.xml.

Research for this post was provided by Alvin Ubiera and the Dynamics 101 SharePoint 2013 training center

Dynamics 101 (2 Posts)

Leave A Response »