Introduction
Content Types are set of columns grouped together to serve a specific purpose.
A content type is a group of reusable settings of shared attributes and behaviours for a specific kind of content. It mainly used for defining item type, documents, list items, media files & folders.
While creating a custom content type child content type must be derived from the one of existing parent content type such as Image, Task, Document or Item. Once it is created in a site, a custom content type is available in that site and in all sites nested under that site.
To make a content type most widely available throughout a site collection, define it in the content type gallery of the top-level site. In the On-Premise environment of Share Point a custom content type can be also created inside a content type hub that is defined in a managed metadata service instance.
In this article, you will learn how we can create content type using Visual Studio and PowerShell for On-line and On-Premise environment.
Prerequisites
- Share-Point 2019 On-Premise Environment
- Share-Point Office 365 Tenant
- Visual Studio
- Share-Point Management PowerShell
Content Type Creation for On-Prem Environment Using Visual Studio
Open Visual Studio and create a new project.
Select SharePoint 2019 Empty Project - C# (Language).
Enter the Project Name. In our case, I created the Project Name as CustomContentType.
In the Next Screen, we need to establish the connection between CustomContentType project with our SharePoint On-Premise environment.
Note
SharePoint 2019 environment doesn’t support the sandboxed solution, we need to deploy our application at the Farm Level as a Farm Solution.
Once the project is created, we will have the project solution ready. During this creation, our SharePoint Application comprises of 2 key things or also known as special node.
- Feature – It’s a container of extension of one or more SharePoint features.
- Package – Single File which can be deployed and reusable.
Add New Item to the SharePoint Project (Ctrl+Shift+A) Select Content Type.
Parent Inheritance of Content Type
Even with the custom content type creation, it needs to be inherit from one of the available existing content types that is available in our site collection.
Note
In our application we have selected the Document as Parent Content Type and finish.
Once the Item is created it will create a Feature in the Feature Folder explicitly by default and our created content type will be placed in the Package Folder.
Content Type Name
|
It displays the Name of our Content type.
|
Parent Content Type
|
It displays which parent content type we inherited to derive this new custom content type.
|
Group Name
|
To which parent group this content type needs to be added there are many group names available such as Document Content Types, List Content Types, Folder Content Types, Custom Content Types etc.
|
Configuration Settings
|
Inherit the columns from Parent Content Type
If you want to inherit the same column from the content type, we need to select this option.
Set to read-only
If the content type needs to be read-only this option needs to be enabled. If this enabled, we cannot able to modify the columns that available with this content type.
Hide from the new buttons in list views
|
Configuring Columns
- Display Name: Which is nothing but the Display Name of the Column which we going to Create.
- Type: Column Type information whether it is Single Line of Text, Number, Lookup or etc.,
- Required: Whether the column is required or not while use submitting a record using this custom content type.
Build and deploy the SharePoint solution.
Open our SharePoint site. Go to Site Settings à Site Content Types under Web Designer Galleries. Our Custom Created Content Type will be visible.
Content Type Creation for Online Environment Using Powershell
While executing the Script if we ended up with the below exception it is stating that the PnP Powershell module is not available in our system hence it couldn’t able to recognize the Powershell commands.
Download Link
- $SiteCollectionUrl = https:
- $CustomContentType ="Sai" #Name of our Content Type
- #Description to our Content Type
- $CustomContentTypeDescription ="Custom Content Type Demo"
- #Group Name of the Content Type
- $CustomContentTypeGroupName = "Custom Content Type"
- #Connecting to the SharePoint Site & Adding the Content Type.
- Connect-PnPOnline -Url $SiteCollectionUrl -Credentials (Get-Credential)
- Add-PnPContentType -Name $CustomContentType -Description $CustomContentTypeDescription -Group $CustomContentTypeGroupName
Code Snippet Execution