Monday, April 1, 2013

How to Rename SharePoint Column Programmatically

Here is how we can rename SharePoint list or site field or column programmatically with PowerShell and C# object model code:

PowerShell Code to Rename a SharePoint Field:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$Web= Get-SPWeb ""

#Get the "Risk Metrics" List
$list= $web.Lists.TryGetList("Risk Metrics")

#Get "Project Name" Field
$field = $list.fields | where {$_.Title -eq "Project Name"}

#Set Field Display Name and Update
$field.Title ="Program Name"

Rename a SharePoint Field Programmatically (C#):

           using(SPSite site=new SPSite(""))
                //Get the "Risk Metrics" List
                SPList list = site.RootWeb.Lists["Risk Metrics"];

                //Get "Project Name" Field
                SPField field = list.Fields["Project Name"];

                //Set Field Display Name and Update
                field.Title = "Program Name";

                //You can also use: list.Fields["Project Name"].Title = "Project Name";

PowerShell to change field display name in SharePoint site collection:
Add-PSSnapin "Microsoft.SharePoint.Powershell" -EA SilentlyContinue

$SiteURL = ""
$OldColumnName ="Department"
$NewColumnName ="Entity"

#Get the Site
$site = Get-SPSite $SiteURL

 #Iterate through each web (Sub-Site)
 foreach ($web in $site.AllWebs)
  #Array to Hold Lists with specific column
  $ListsToProcess= @()
  #Get All Lists
  $Lists = $web.Lists
  #ITerate through each list
     foreach ($list in $lists)
   #Iterate through each column
         foreach ($column in $list.Fields)
    #Check for the specific column
             if ($column.Title -eq $OldColumnName)
     Write-Host "Found the Column in list: " $list.Title " at "$web.Url
     #Send it to an Array
  #Process each list and rename the columns
  foreach ($list in $ListsToProcess)
   #Get the Old column by its name
   $column = $list.fields | where {$_.Title -eq $OldColumnName}
   #rename sharepoint list column powershell
   $column.Title = $NewColumnName

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

1 comment :

  1. Hi Salaudeen,

    How to rename the column/field using sharepoint webservices ?Can i do that ?


Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...