SharePoint list, Content Types in SharePoint 2013

Before developing the lists, SharePoint content types and site columns we need to understand what is SharePoint list, content types etc. And why do we have to create them in the SharePoint site.
Lists are data containers in  SharePoint, where you can store the data of different data types. In SharePoint this content will get stored in the database and the content is very important for any organization.
So whenever you start developing any project the important question you need to ask the client is what type of data or different data types  you're maintaining or want to maintain in future. That data may be Sales documents, Finance documents, Project proposals and implementation documents, maintenance documents etc. These are all different kinds of data. In normal scenario document is a just a document, but in SharePoint you can have types of documents. Each type of document has its own metadata. The way you organize the data and persisting it and entire editing experience is a great thing in SharePoint.To manage the content we will create content Types.
I hope you got a little bit of understanding about the importance of SharePoint list and content type in SharePoint.
Let's move on to develop the artifacts using visual studio 2012.

Site Columns:

Whenever you develop the SharePoint list and Content type, first develop required site columns that will be used while developing SharePoint lists and Content types.

what are site columns?

A site column is a reusable column definition, or template, that you can assign to multiple lists across multiple SharePoint sites. We will see how we achieve this.
Let's open the Visual studio 2012.
Create a new project by selecting the SharePoint 2013 - empty project template from the SharePoint solutions under office/SharePoint section. Please see below figure for reference.
SharePoint 2013 - empty project
Enter the name of the project and click OK.
SharePoint 2013 - project wizard
Enter the site URL and click on validate make sure the connection is successful then select the "Deploy as s farm solution"  and click on Finish.
It's time to add the required site columns to the project. To do that right click on the project click on Add -> New Item, the below screen will come up from that select Site column, enter column name and click on Add button.
The column will get added to the project and the required XMl file will get generated.
Site-column
In the same way you add all the required columns. In this example I have added two site columns i.e. Team Name, Task assigned.
Once you add the site column it will generate the Elements.xml file where you can change the properties of the field. Please see the below default code snippet which will generate.
1234567891011
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field
ID="{779bdd44-c459-49cd-8265-3190420c7633}"
Name="Team_x0020_Name"
DisplayName="Team Name"
Type="Text"
Required="FALSE"
Group="Custom Site Columns">
</Field>
</Elements>
view rawElements.xml hosted with ❤ by GitHub
You can change the Required and Group properties of filed according to your requirement.
Now we are ready with the site columns required for our site. Now its time to create Content Types.

Content Type:

Content types are used to manage the different types of metadata (columns).
It is a reusable collection of metadata with event receivers, workflows, other settings for the group of items in a SharePoint list or library.
To create content type, right click on the project which has been created above step, click on Add -> New Item, the screen will come up from that select Content Type and enter the name of your content type and click Add.
content_type
Select the base content type which you want to inherit from. I am selecting Item content type as a base one.
content_type_wizard
Click finish. It will create a content type where you can add your site columns which has been created above.
Once you create the content type, it will show the VS designer view with two tabs Columns and Content Type.
From the Columns section you can add the site columns.
See in the below figure when you enter "a" it is displaying all values which matches with "a". This detail will get populated based on site columns available in the site and site columns you have added to the solution.
content-type
Once you have added all the site columns like below screen click on save.
If you want to delete any column which you have added, right click on that column name it will show small pop up "Delete-Del" click on that to delete it.
Content-type-column
Move on next tab content type. In the content type section you can enter your content type name, description, group name and there are three more properties.
Inherits the columns from the parent content type, you can check or uncheck that option based on your requirement.
content_type_settings
After completion of your required settings of your content type, click on save. Try to open the Elements.xml file, when you open it it will ask to close the content type designer view.
If you open the Eelements.xml file of your content type, you can observe that everything has been created for you. Please see the below code snippet for reference.
12345678910111213141516171819202122232425262728
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Parent ContentType: Item (0x01) -->
<ContentType ID="0x0100118703F0484042118516B33BD9488ECB" Name="ContentType-Object Model" Group="SharePoint-Journey" Description="My Content Type" Inherits="TRUE" Version="0">
<FieldRefs>
<FieldRef ID="{a4a8c94a-6a0d-4ef2-880d-a049720e2a73}"
DisplayName="Team Name"
Required="TRUE"
Name="Team_x0020_Name" />
<FieldRef ID="{2f6753f2-1584-477a-868e-d75ead1aaa07}"
DisplayName="Task assinged"
Required="TRUE"
Name="Task_x0020_assinged"
NumLines="6"
Sortable="FALSE" />
<FieldRef ID="{64cd368d-2f95-4bfc-a1f9-8d4324ecb007}"
DisplayName="$Resources:core,Start_Date;"
Required="TRUE"
Name="StartDate"
Format="DateOnly" />
<FieldRef ID="{8A121252-85A9-443d-8217-A1B57020FADF}"
DisplayName="$Resources:core,End_Date;"
Required="TRUE"
Name="_EndDate"
Format="DateTime" />
</FieldRefs>
</ContentType>
</Elements>
view rawElements.xml hosted with ❤ by GitHub

SharePoint List:

So far you have build site columns and content type. Now using these two we need to build the list.

Create a list by adding a new item to the project.
List
Enter the name of the list that you want to create and click on Add. It will open the wizard to choose the list settings.
Use the default (Blank) template to create the list and click finish.
create_list
It will open the list designer in visual studio where we can add the required columns from columns tab or click on the content type button at the bottom of the columns tab to select the content type that will be used to create a list.
As a standard practice we will create the columns by selecting the content type, so click on content types button from columns tab.
create_list
Choose the content type from the dropdown menu, this populate the all content types available in the SharePoint site and content types that we have added to the project. You need to add the content type which you created before.
create-list
Once you select the content type, click ok. It will populate the site columns which has been used for that content type, see the below screen.
create_list
Go to next tab i.e. Views. Here you can set the row limit and available fields in that  of that particular view. By default you will have Allitems view, you can add the views which you want to customize it.
List-Views
Next click on the List tab to change the title, URL, description of the list. There are two options Display list at quick launch and Hide list from browser, based on your requirement you can change that.
create_list
Once you change the settings of the list  the Elements.xml file of list instance will get modified.
Please see below snippet for reference.
12345678910
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance Title="TeamDetails"
OnQuickLaunch="TRUE"
TemplateType="10000"
Url="Lists/TeamDetails"
Description="My List Instance">
 
</ListInstance>
</Elements>
Once you complete everything, build the project and deploy it to your SharePoint site by clicking a deployment option from the project.
build-list-project
After successful deployment you can check your SharePoint list, content type and site columns which you have built here in your SharePoint site.
Check here for the video of developing SharePoint list, Content Types and site columns in SharePoint 2013.

Conclusion:

We have seen the capabilities of visual studio designer in visual studio 2012 to develop the SharePoint list, Content types and site columns for SharePoint 2013 with less effort and time. That makes developer's life much easier.
- See more at: http://www.sharepoint-journey.com/sharepoint-list-content-types-and-site-columns.html#sthash.dSntuzMA.dpuf

Comments