Deploy Site Columns, Content Type And List To SharePoint Using SharePoint Hosted Add-in

SharePoint hosted apps can be used to deploy Lists, workflows, site columns, content types, custom pages and other SharePoint artifacts. SharePoint Hosted App is now renamed as SharePoint Hosted Add-in. In this article we will see how to,

  • Create a set of site columns
  • Create a content type and add the site columns to the content type and
  • Create a list based on the new content type

Let’s get started with the SharePoint hosted app creation with Visual Studio,

new

  • Select the App for SharePoint 2013 template.

    select

  • Specify the Site URL for debugging and mention the app type as SharePoint hosted.
Add Site Column

add
  • Right Click the Project name and select Add ->New Item,

    New Item

  • Since we will be first creating site columns select the Site Column item into the project.

    code

  • You will get an Elements.xml file along with the site column item. In the elements.xml add field tags for each of the site columns you would like to add to the Site. Make sure you specify the Data Type correctly. ‘Name’ will be the internal name and ‘Display Name’ will be the name shown in the UI.

Add Content Type

type

  • Now again right click the project and select Add->New item. This time choose Content Type.

    type

  • Specify the parent content type as Item.

    content

  • Once the Site Columns and Content Type items are added the project solution structure would resemble as above.

    structure

  • Once the Content Type item is available in the solution structure double click on it to pop up the above property window. Click on the highlighted section to add the already created site columns to the Content Type.

    type

  • Site columns added to the Content type will look as above. You can add more or remove the already added ones.

Add a List

list

  • Now let’s add a list. You can right click the project and select Add->New Item .Select List from the available options.

    Add

  • Specify the list name and the list template name which is a custom list in this example.

    list

  • Double Click on the created list. Now add the already created content type to the list by clicking on Content Types button. Select the appropriate content type.

    list

All the columns present in the content type will be added to the list.

columns

Now the site columns and Content types have been created. We have also provisioned a list based on the site column and content type. Let’s deploy the Share Point hosted add-in by clicking on Deploy.

trust

It will ask you whether to trust the app. Select Trust It.

Trust

The Share Point Hosted Add-in is now available in the site. You can add the data to the list by populating the site columns with data.