Wednesday, April 15, 2015

Creating SharePoint Columns Programatically Using C#

As a SharePoint developer you can use SharePoint API to create columns programmatically in Lists or Document Libraries. You can set the different properties for the column. Followings are few snippets to create SharePoint column programmatically using C#.

Single line of text

Represents a column that contains a single line of text.


Multiple lines of text

Represents a column that contains a multiple line of text.

Choice (menu to choose from)

Represents a column that contains choices. It can be single select or multiple select. For single select Choice field renders Dropdown list or Radio button list and for multiple select it renders Checkbox list.

Number (1, 1.0, 100)

Represents a column that contains numbers. You can use DisplayFormat property to set the allowed number of decimal.

Currency ($, ¥, €)

Represents a column that contains currency. You can use DisplayFormat property to set the allowed number of decimal. You can use CurrencyLocaleId property to set the currency symbol. You can find full list of Locale Ids here

Date and Time

Represents a column that contains a DateTime value. You can use DisplayFormat property to set the date format.

Lookup (information already on this site)

Represents a column that contains a information from other List/Document Library from current site.

Yes/No (check box)

Represents a column that contains Boolean value.

Person or Group

Represents a column that contains a user or group information.

Hyperlink or Picture

Represents a column that contains a Url information. It can be Hyperlink or Picture Url.

Calculated (calculation based on other columns)

Represents a column that contains a calculated value based on other columns.

Managed Metadata

Represents a column that contains information from Term Store.