By Sharada Harnal on Apr 7, 2015, 6:13:48 AM
SharePoint lists are easy to create by any IT Pro User without any assistance of a developer. List is often the primary source of data for solutions and apps. They can be easily accessed through API’s and support full CRUD (create, read, update and delete) operations. However, there are often scenarios where it makes more sense to automate the creation of lists by using a SharePoint solution.
New lists can be created in solutions or apps using a feature that contains a ListInstance element. The example below will create a new picture library for storing Christmas pictures
Declarative approach is simple as it uses tools integrates with Visual Studio 2012.
No graceful way to handle conflicts. For example, if we try to activate a feature to create a list with the same title as an already existing one, the feature activates successfully, but the feature’s attempt to create a list silently fails due to the conflict. For apps, this is not a problem because each app instance can create its own set of lists.
Depending on the requirement, we can use any of the below three approaches for creating lists using code
- More control when creating list programmatically, we can query the list collection of the current site to check if there is an existing list with the same title before attempting to create a new list.
- More control over configuring properties when compared to declarative. This is to support attachments and allow versioning.
Server Side Object Model:
When we can create Farm solutions, mostly for on premises implementation, the solution must be physically deployed on the server.
Client Side Object Model:
Provides access to SharePoint content without installing code on the server that runs Microsoft SharePoint Foundation
Allows you to integrate SharePoint capabilities into code that runs remotely in client-side or server-side applications that run on computers where SharePoint 2013 has not been installed