SharePoint list, Content Types in SharePoint 2013


Developers can develop the SharePoint list, content types, site columns in SharePoint 2013 with less effort and time using visual studio designer, which is one of the new features in visual studio 2012.

In this post we will use the visual studio designer to create lists, content types and site columns in Visual studio 2012 for 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.

Do you want to learn more about SharePoint Online Development? Click the image below and enroll in the FREE course.

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.

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.

Do you want to learn more about SharePoint Online Development? Click the image below and enroll in the FREE course.

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.

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.


Do you want to learn more about SharePoint Online Development? Click the image below and enroll in the FREE course.


› SharePoint list, Content Types in SharePoint 2013

About Author

Devendra Velegandla is a four-time recipient of Microsoft's Most Valuable Professional (MVP) award (2014-2017) for Office Servers and Services MVP and  SharePoint Server.He received the MCC award for his contributions in Microsoft MSDN/TechNet forums.He loves sharing articles, videos and tutorial on SharePoint and Office 365.


If you found this post helpful, please share with your friends!!


Join 6,000 subscribers and receive instant access to

Devendra's Library of Resources for SharePoint Developers