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

How to create site definition using Visual Studio 2013 in SharePoint 2013?
InfoPath alternatives for form designing SharePoint

In this post we will discuss how we can create a site definition using Visual studio 2013 in SharePoint 2013. SharePoint works like a foundation for a new SharePoint site. In a site definition we can put preconfigured lists, content types, event receivers, images, and other items. By default SharePoint provides various out of box default site definition.

Also you can check out:
– Deploy Administation approved InfoPath forms in SharePoint 2013

– Get list of pages using a particular page layout using PowerShell in SharePoint 2013

– Get All Attachments From SharePoint 2013 List Item using Rest API

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

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

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

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

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.

 How to create site definition using Visual Studio 2015 in SharePoint 2016?
How to create site definition using Visual Studio 2015 in SharePoint 2016?

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:

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

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

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

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

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

To add few options to the Choice column open the Schema.xml file and add 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.

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

How to create site definition using Visual Studio 2013 in SharePoint 2013?Then right click on the solution and click on Deploy solution. The solution will be deployed to the site site collection.

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

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

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

 How to create site definition using Visual Studio 2013 in SharePoint 2013?
How to create site definition using Visual Studio 2013 in SharePoint 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.

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

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

About 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

View all posts by Bijay Kumar →

Leave a Reply