Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to rename an enterprise keywords column in a specific list of a subsite. In a Feature Activated event receiver i tried to set the column's display name by setting its title using the following method:

SPField field = list.Fields["Enterprise Keywords"]; 
field.Title="Test"; 
field.Update(); 
list.Update();

when debugging everything seems to be ok, the new name appears but when i navigate to the list, the Enterprise Keywords column is the same.

I tried using the reflection method, as suggested in a post i read, but this fails as well.

private static void SetFieldDisplayName(SPFieldLookup continuingProjectLookup, string displayName)
{
    Type baseType = continuingProjectLookup.GetType().BaseType;
    object obj = baseType.InvokeMember("SetFieldAttributeValue", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,    null, continuingProjectLookup, new object[] { "DisplayName", displayName });
    continuingProjectLookup.Update();
}

Although in debugging it seems ok, in the UI it doesnt change.

The only possible way i found to have this column renamed is if i change the site collection's Enterprise Keywords column name, but then it also changes the name to all the other lists, which i don't want to happen.

Is there no better way?

`

share|improve this question
add comment

1 Answer

It is recommended to reference the field by it Internal Name or ID

In your code there is no any guarantee that you are really modifying title for Enterprise Keyword field, because Display Name is used for reference

So, below is updated code to change Enterprise Keyword field title:

//Rename title for Enterprise Keyword field in List
 public static void RenameEntKeywordInList(SPList list, string newTitle)
 {
     var field = list.Fields.GetFieldByInternalName("TaxKeyword");
     field.Title = newTitle;
     field.Update();
 }

There is known issue related with updating field title when the language of current Thread UI is different from language of the web

In that case use the following method:

private static void SetFieldDisplayName(SPField field, string displayName)
{
   var baseType = field.GetType().BaseType;
   if (baseType != null)
       baseType.InvokeMember("SetFieldAttributeValue", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, field, new object[] { "DisplayName", displayName });
   field.Update();
 }

Usage:

var field = list.Fields.GetFieldByInternalName("TaxKeyword");
SetFieldDisplayName(field, "New Enterprise Keyword Name");
share|improve this answer
    
Hey Vadim, Thanks for answering, but this method still produce the same result. When i debug everything seems to be great, once i navigate to the list - field name stays the same... :( –  JohnnyT May 3 '13 at 14:24
    
Hey @JohnnyT, could you please try to call Update method for field like this: field.Update(true); // propagate changes to lists that implement the field –  Vadim Gremyachev May 3 '13 at 14:33
    
same reaction :( if i try to change any other field in that list, it works flawlessly.. only the Enterprise Keywords field refuses to change. –  JohnnyT May 3 '13 at 15:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.