Introduction
A site column is the most basic element you can add to a SharePoint site. A site column represents a type of data, such as a first name, last name, email id, phone number, and address, in a personal contact list. In this article, I will explain how to create site columns in SharePoint 2013, using Visual Studio.
Pre-Requisites
- Open Visual Studio.
- Open New Project dialog box. Expand Office/SharePoint node and then choose "SharePoint Solutions".
- Select the "SharePoint 2013 – Empty Project" template. Name the project as ExampleSharePointProject.
- Choose the "Deploy as a farm solution" option and click Finish.
- ExampleSharePointProject SharePoint project gets created.
Create Site Columns
- Right click on ExampleSharePointProject -> Add -> New Folder. Name it as "Site Columns".
- Right click on "Site Columns" folder -> Add -> New Item.
- Add "Site Column" from the "Add New Item" window. Name it as “FirstName”.
- Element.xml is created by default in FirstName site column field.
- “ID” attribute is the Unique GUID of the site column.
- “Name” attribute is the internal name of the site column.
- “DisplayName” attribute is the display name of the site column.
- Type of the column is decided by “Type” attribute. e.g., Text, Choice, Number, Currency, lookup, etc.
- “Required” attribute is the site column value that tells if it is required or not required.
- “Group” attribute defines the groups in which the site column appears.
- Once you create a site column, you will notice that Visual Studio has automatically added a Feature to the project and included the new site column “FirstName” in it.
- Build and deploy the SharePoint solution.
- Open SharePoint site. Go to “Site Settings” -> “Site Columns” under Web Designer Galleries. The list of all the site columns present in the site appears. Select the “Custom Site Column” group. Our “FirstName” site column appears.
Summary - Thus, you have learned how to create site columns in SharePoint 2013, using Visual Studio.