SharePoint Pals
 | Sign In
How to Create a Site Column in SharePoint 2010
by Gopal Muthukrishnan 19 Feb 2013
Author
SharePoint Developer, SharePoint Frontier
Visits   
Today  :   1     Total  :    24559

This article describes how to create a site column in SharePoint 2010 by using SharePoint UI, Programmatically, PowerShell and SharePoint Designer. By this, you can choose your own choice to create a Site Column in your environment.

Site column

SharePoint 2010 has a site column entity that allows you to reuse columns across multiple lists.  If you create a new column in custom List, you can use the column in that list alone. Suppose if you create a site column you can use the column in any list or library within your Team Site

1. Create Site Column in SharePoint UI

2. Programmatically create Site column

3. Create Site Column by PowerShell

4. Create Site Column by SharePoint Designer

To create a new site column in a list or library

Step 1:-

Choose Site Actions

clip_image001

Step 2:-

Click Site Settings from Site Actions from Top Level Site

clip_image003

Step 3:-

Click the Site Columns from Galleries

clip_image005

Step 4:-

Click the Create link to create a new column.

 clip_image007

Step 5:-

Enter the name for your site column in Column Name field.

Step 6:-

Select the column type by clicking the radio button.

Step 7:

Then Select Custom Column from Existing groups dropdown. This site column must be a member of this group.

clip_image009

Step 8:-

Click OK button. Your site column will be listed in site columns.

Programmatically create Site Column in SharePoint

Adding a New Site Column in SharePoint Site

 SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                {
                    SPWeb web = site.RootWeb;
                    //Create Site Column
                    string SiteColumnName = "India";
                    //Add choice Field "India"
                    if (!web.Fields.ContainsField(SiteColumnName))   
                    {
                        string countryField = web.Fields.Add(SiteColumnName, SPFieldType.Choice, false);
                        //Set the Field Properties
                        SPFieldChoice CityInIndia = (SPFieldChoice)web.Fields.GetField(SiteColumnName);
                        //Set the group for the Site column
                        CityInIndia.Group = "States";    
                        //Add the choices
                        string[] States = new string[] { "TamilNadu", "Kerala", "Andhra Pradesh", "karnataka"};
                        CityInIndia.Choices.AddRange(States);
                        //Set the default value
                        CityInIndia.DefaultValue = "TamilNadu";
                        //Set Fillable value
                        CityInIndia.FillInChoice = true;
                        //Update the field
                        CityInIndia.Update();
 
                    }
                }
            });

Create a New Site column by PowerShell

Code for creating a New site Column through PowerShell Script

 $site = Get-SPSite -Identity "http://sfs03-pc:12121/sites/Samples/"
 $web = $site.RootWeb 
 $fieldXML = '<Field Type="Text"
 Name="EmpName"
 Description="Employee Name Column Info."
 DisplayName="EmpName"
 Group="EmployeeInformation"
 Hidden="FALSE"
 Required="FALSE"
 ShowInDisplayForm="TRUE"
 ShowInEditForm="TRUE"
 ShowInListSettings="TRUE"
 ShowInNewForm="TRUE"></Field>' 
 $web.Fields.AddFieldAsXml($fieldXML)
 $web.Dispose()
 $site.Dispose()

Then check your Gallery you will find the site column in the name of EmpName under the group of EmployeeInformation

Modifying the Existing Site column by PowerShell

Code for Modifying the Existing site Column through PowerShell Script

$site = Get-SPSite -Identity "http://sfs03-pc:12121/sites/Samples/"
$web = $site.RootWeb 
$field=$web.Fields["EmpName"]
$field.Type= "Choice"
$field.Update($true)
$web.Dispose()
$site.Dispose()

Then check your Gallery, EmpName column type will change to Choice type

Create a new site column in Sharepoint Designer

Open your Site in Microsoft SharePoint Designer

Step 1:-

Click Site Columns

clip_image001[4]

Step 2:-

Click the New Column from file Menu and the choose its Type

clip_image002

Step 3:-

Enter The Column Name in the TextBox and the Choose group

clip_image003

Step 4:-

Click save Button to find your Created SiteColumn

clip_image004

blog comments powered by Disqus

SharePoint Pals

Pals
SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile

Training

Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community




SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to articles@sharepointpals.com in a word document.

Related Resources

Recent Tweets

Twitter January 15, 00:25
How To Enable Target Value And Actual Value In #D3 Gauge Chart https://t.co/VxSi4QnNrC

Twitter January 15, 00:24
How To Open #SharePoint List Hyperlink Column In Modal #Popup Window https://t.co/EQ7HkoZDkX

Twitter January 15, 00:24
Quick Introduction To #Asp.NetCore And It’s Features https://t.co/zAXObHCFpH

Twitter January 15, 00:22
How To Configure #PerformancePoint Services To Use Secure Store In #SharePoint 2013 https://t.co/LEwnUoI7EY

Twitter January 15, 00:21
How To Block Or Disable #Office365 Services https://t.co/Yvp2VPFIRP

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation