How to create site definition using Visual Studio 2013 in SharePoint 2013

This SharePoint 2013 tutorial explains, how to create a site definition using Visual Studio 2013 in SharePoint 2013. The same way we can create a site definition using visual studio 2017 using SharePoint 2016.

SharePoint works as a foundation for a new SharePoint site. In a site definition, we can put pre-configured lists, content types, event receivers, images, and other items. By default, SharePoint provides various out of box default site definition.

Create custom site definition in sharepoint 2013 programmatically

Follow the below steps to create a site definition in SharePoint 2013 programmatically using Visual Studio.

Open visual studio 2013, then click on File -> New -> Project. The form list of templates go to Templates -> Visual C# -> Office/SharePoint -> SharePoint Solutions. In the new project dialog box, choose the SharePoint 2013 – Empty Project. Give a name, location as well as choose .NET Framework 4.5. It looks like below:

create custom site definition in sharepoint
create custom site definition in sharepoint

Then in the SharePoint customization wizard, give a local SharePoint site for debugging. And then choose to Deploy as farm solution as shown in the fig below:

create custom site definition in sharepoint 2013 programmatically
create custom site definition in sharepoint 2013 programmatically

Then we will add a site definition to the project. Right-click on the Project and then Add New Item… Then in the Add New Item dialog box, here choose Site Definition (Farm Solution only) template.

create custom site definition in sharepoint 2013
create custom site definition in sharepoint 2013

Then we will add a list definition to the site definition. So Right-click on the Project -> Add -> New Item and then choose List as shown in the fig below:

create custom site definition in sharepoint 2013 programmatically
create custom site definition in sharepoint 2013 programmatically

Then give a name for the list and choose to create a customizable list template and a list instance of it as shown in the fig below:

create custom site definition in sharepoint 2016 programmatically
create custom site definition in sharepoint 2016 programmatically

In the list definition, we are going to add a few columns. Here I have added two single lines of text and one Choice column. The schema will look like below:

create custom site definition in sharepoint 2013
create custom site definition in sharepoint 2013

To add a few options to the Choice column open the Schema.xml file and add a few options to the Choice column.

<Field Name="Department1" ID="{8f16fc3c-f596-4281-b949-4d075f2c48da}" DisplayName="Department" Type="Choice" >
<CHOICES>
<CHOICE>IT</CHOICE>
<CHOICE>Finance</CHOICE>
<CHOICE>HR</CHOICE>
</CHOICES>
</Field>

Then we have to modify the onet.xml file to give reference to the list. In the onet.xml file in the Lists, node add your list details.

<List Title="Employees" Type="10000" FeatureId="72fe910d-3576-4e45-ad71-fb41d95d53f0"></List>

The onet.xml file looks like below:

<?xml version="1.0" encoding="utf-8"?>
<Project Title="MyEnjoySharePointSiteDefinition" Revision="2" ListDir="" xmlns:ows="Microsoft SharePoint" xmlns="http://schemas.microsoft.com/sharepoint/">
<NavBars>
</NavBars>
<Configurations>
<Configuration ID="0" Name="MyEnjoySharePointSiteDefinition">
<Lists>
<List Title="Employees" Type="10000" FeatureId="72fe910d-3576-4e45-ad71-fb41d95d53f0"></List>
</Lists>
<SiteFeatures>
</SiteFeatures>
<WebFeatures>
</WebFeatures>
<Modules>
<Module Name="DefaultBlank" />
</Modules>
</Configuration>
</Configurations>
<Modules>
<Module Name="DefaultBlank" Url="" Path="">
<File Url="default.aspx">
</File>
</Module>
</Modules>
</Project>

We can retrieve the Feature ID from the Feature1.feature file.

create custom site definition in sharepoint 2016
create custom site definition in sharepoint 2016

Then right-click on the solution and click on Deploy solution. The solution will be deployed to the site collection.

Go to the Site Contents page and then click on a new subsite. There in the Select a template section you will be able to see the custom site definition.

create custom site definition in sharepoint using visual studio
create custom site definition in sharepoint using visual studio

Once you will give the details to create a site, the site will get created like below:

create custom site definition in sharepoint using visual studio 2013
create custom site definition in sharepoint using visual studio 2013

And if you will go to the Site Contents page, then you will be able to see the list got created which we have added to the site definition.

create custom site definition in sharepoint using visual studio 2017
create custom site definition in sharepoint using visual studio 2017

You may like following SharePoint visual studio tutorials:

Hope this SharePoint 2013 tutorial explains, how to create a custom site definition using a visual studio in SharePoint 2013/2016.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

>