How to Change the Display Name of OOB Column

Hello All,

Today I am going to post small and very simple post – “How to change the display name of OOB column using object model”. Since I struggled for some time to change the display name of OOB title column in one of the my custom list I thought I should share this.

In our project we have our custom list and list content type is derived from ITEM content type (0x01). So we have Title column from ITEM content type. But customer want to change the display name of Title column say “Customer Title”. So I thought I will simply do this change in my content and it will work like

  1. <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Customer Title" Required="TRUE"/>  
But unfortunately it didn’t work. I did some research, some blogs says that change the display name in Schema.xml of list definition in <Fields> section for Title field but for us this is also not a solution since we have created our list using object model in FeatureActivated() of our feature receiver. Again did some research and able to change the display name of OOB title column. We could do this by updating “Title” property of respective SPField instance.

Following is the sample code
  1. if (list.Fields.ContainsField("Title"))  
  2. {  
  3. SPField fldTitle = list.Fields["Title"];  
  4. fldTitle.Title = “My Custom DisplayName”;  
  5. fldTitle.Update(true);  
  6. }  
and following is the full code.
  1. public class MyCustomerEventReceiver : SPFeatureReceiver  
  2. {  
  3.  
  4.         #region Overload Methods  
  5.         public override void FeatureActivated(SPFeatureReceiverProperties properties)  
  6.         {  
  7.             SPSite site = properties.Feature.Parent as SPSite;  
  8.             if (site != null
  9.             {  
  10.                 SPWeb web = site.RootWeb;  
  11.                 SPList list = web.Lists.TryGetList(“My Custom List”);  
  12.                 bool flag = web.AllowUnsafeUpdates;  
  13.                     if (list == null
  14.                     {  
  15.                         web.AllowUnsafeUpdates = true;  
  16.                     Guid guid = web.Lists.Add(My Custom List, "Custom List", SPListTemplateType.GenericList);  
  17.                         list = web.Lists[guid];            
  18.                       if (list.Fields.ContainsField("Title"))  
  19.                         {  
  20.                             SPField fldTitle = list.Fields["Title"];  
  21.                             fldTitle.Title = “My Custom DisplayName”;  
  22.                             fldTitle.Update(true);  
  23.                           
  24.                         }  
  25.                      list.Update();  
  26.                     }  
  27.             }  
  28.         }  
  29.   
  30. }  
Thanks!

Feel free to comment / feedback if any or if you have any query.
Ebook Download
View all
Learn
View all