This SharePoint tutorial explains, how to create a list definition and list instance in SharePoint 2013 using Visual Studio 2013. The same way we can create a list definition in SharePoint 2016 using visual studio 2017.
Here we will create a SharePoint farm solution rather a sandboxed solution for this demo. Sandboxed solutions have been deprecated in SharePoint 2013, so we should avoid using the Sandboxed solution in SharePoint 2013. But Sandboxed solutions will still work on SharePoint 2013.
You can check an article on Differences Between Sandboxed and Farm Solutions in SharePoint 2013.
Unlike SharePoint 2010, SharePoint 2013 or SharePoint 2016 cannot be installed in a client operating system like Windows 8, 10, etc. So if you want to develop solutions using Visual Studio 2013, make sure you have Visual Studio installed on the same server where you have SharePoint 2013 installed.
Create a custom list definition or list instance in SharePoint using Visual Studio
Follow the below steps to create a custom list definition or list instance in SharePoint using Visual Studio 2013/2015/2017.
Open Visual Studio 2013 then File -> New -> Project. In the New Project dialog box, you will be able to see the lots of project templates. From the left side you can go to Installed -> Templates -> Visual C# -> Office/SharePoint -> SharePoint Solutions. Then in the right side choose SharePoint 2013 – Empty Project.
Then give a name for the project location where you want to Save and the name of the Solution and then click on OK. Here make sure you have selected .NET Framework version 4.5 is selected. Because .NET Framework 3.5 is not supported in SharePoint 2013. The dialog box will look like below:
Then in the next SharePoint Customization Wizard, give a local site URL for debugging. This site can be used for debugging and testing the project. This should be a local SharePoint site and should be available. Also, you can use the Validate button to validate the site.
Then you have two option to select which type of solution you want to develop, here I have chosen a farm solution. But make sure you have SharePoint Administrator privileges to deploy the solution. It should look like below:
Once you will click on OK, Visual Studio will create the solution for you. There you will be able to see the Features folder and Packages folder. Features folder will help in adding new features to a SharePoint project.
Since we have created an Empty SharePoint project, so the Feature folder is empty. Packages folder will help in building the solution package (.wsp) which can be used to deploy the solution to other servers apart from development servers like production or staging server.
Now we will add a list to the project. Right-click on the Project -> Add -> New Item… This will open the Add New Item dialog box. From the Office/SharePoint templates select List from the available templates as shown in the fig below:
In the next dialog box, it will ask for list settings like, Give a name for your list. And choose whether you want to create a customizable list template or a list instance based on the existing list type. Here I have chosen to use the Custom List template. It looks like below:
Once you add the list instance, a feature will also be automatically get created. The feature scope will be Web and the list instance will be added automatically to the feature. Now if you look at the solution explorer it will look like below:
Now let us do some customization to the design view of the list instance. There are 3 tabs in the design view: Columns, Views, and List.
In the Columns view, you will be able to see by default the Title column which comes in the Custom list template. Here I have added another single line of text column to it which I named as the First Name.
You can add a number of the column with different data types in it. If you want to make the column mandatory, just check the required checkbox which is presented in the last. It looks like below:
The next tab is the Views tab, by default, it will show All Items view. Here I have created on view name as My Test View and for this view, I have just added ID, Title, and First Name column and I have set row limit of 10. It will look like the below figure.
The next tab is List tab where you can change the Title, List URL and Description of the list. Here also I have selected the checkbox “Display list at Quick Launch“, so that once the list got created it will appear in the Quick Launch. It looks like below fig:
After this, we will go and create two items for the list instance. Open the Elements.xml file which will look like below.
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <ListInstance Title="MyCustomListDefinition" OnQuickLaunch="TRUE" TemplateType="100" Url="Lists/MyCustomListDefinition" Description="My List Instance"> </ListInstance> </Elements>
Now we can add two items to the list like below:
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <ListInstance Title="MyCustomListDefinition" OnQuickLaunch="TRUE" TemplateType="100" Url="Lists/MyCustomListDefinition" Description="My List Instance"> <Data> <Rows> <Row> <Field Name="Title">Item-1</Field> <Field Name="FirstName">Bijay</Field> </Row> <Row> <Field Name="Title">Item-2</Field> <Field Name="FirstName">Sahoo</Field> </Row> </Rows> </Data> </ListInstance> </Elements>
Now our solution is ready for deployment. Since we are doing the development in development server, right-click on the Solution, then click on Deploy Solution. It will do all the steps required for deployment.
If you want to deploy the solutions to other SharePoint servers where you will not have visual studio then you can see: How to deploy farm wsp solution in sharepoint 2010/2013 using PowerShell?
Once the deployment is over, you can see your solution is deployed in the central administration. Open your SharePoint 2013 central administration, then click on System Settings. Then in the System Settings page, click on Manage farm solutions which are under the Farm Management section.
Here we have created web level feature, we can see the feature by going to Site Settings page Then from Site Actions section click on Manage site features link. We can see the feature already activated like below:
Also in the Site Content, we will be able to see the list got created with the name whatever we have given earlier. f you will open the list, we can see it has the extra columns (First Name) which we have added in the list definition, as well as the two items, are added which we have added. Apart from this, the view is also got created (My Test View) as shown in the fig below:
And the final thing we can check is the list definition should be available for us so that we can create another list by using the template. Click on the gear icon and then Add an App. You can search for the name you should be able to see the app. By using that template we can create lots of lists.
You may like following SharePoint visual studio tutorials:
- How to create site definition using Visual Studio 2013 in SharePoint 2013?
- Steps to create Site column using Visual Studio 2013 in SharePoint 2013
- Create a timer job in SharePoint 2016/2013 Programmatically (Step by Step tutorial)
- Call Web API from SharePoint Online using httpsend workflow activity
- Create a Web API for SharePoint Online and Deploy to Microsoft Azure using Visual Studio (Step by Step tutorial)
- Develop SharePoint workflows using visual studio as SharePoint hosted App
- Create remote event receiver SharePoint Online Step by Step Tutorial
- How to Schedule Azure WebJobs in Visual Studio 2015 for SharePoint Online?
- Create Azure WebJobs for SharePoint Online and Deploy to Microsoft Azure
- Create a provider-hosted add-in in SharePoint Online and host in Microsoft Azure using the Import method
- Create a Custom Action Group using Visual Studio 2015 for SharePoint 2016
Hope this SharePoint tutorial explains, how to create a custom list definition and list instance in SharePoint 2013/2016 using visual studio 2013/2015/2017.
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 SPGuides.com
Download SharePoint Online Tutorial PDF FREE!
Get update on Webinars, video tutorials, training courses etc.