5

The twist to this question is that I am using a localized site - the site is using the Norwegian Team Site template. Hence, the Title column is actually named "Tittel". Presumably, the following should to the trick:

customersList.Fields["Tittel"].Title = "Firma";
customersList.Fields["Tittel"].Update();
customersList.Update();

The code runs without errors, but the display name of the Title column doesn't change. I read somewhere that the TitleResource parameter is involved when multiple cultures are available, so just for kicks I tried

customersList.Fields["Tittel"].TitleResource.Value = "Firma";
customersList.Fields["Tittel"].TitleResource.Update();
customersList.Update();

but no luck. Any ideas?

7
  • Note that attempting to change the value with 'Fields["Title"]' results in a runtime error. May 10, 2012 at 14:29
  • try customersList.Update()? May 10, 2012 at 14:33
  • Yes, I am calling Update on the list immediately afterwards. I'll update the question to emphasize this. May 10, 2012 at 14:34
  • 1
    are you sure you are changing the field that is displayed ? I have seen cases where the original title column has been renamed, or hidden in a content type, and a new Title column has been created. This allowed to defined other properties on the title column. Check your view
    – Steve B
    May 10, 2012 at 15:26
  • The site and column was created just milliseconds before this code is executed, so I am confident that it hasn't been RENAMED...it might have been screwed up by the fact that I use a Norwegian site template, though. The last letters of the URL of the field indicates that it is still named "Title", but I get a runtime exception when attempting to change this property. See Paul's answer + comment and screenshot: i.imgur.com/jW0DB.png May 11, 2012 at 7:16

2 Answers 2

8

To get the field always use the GUID it's the safest. And always put it into a local variable to work with:

var field = customersList.Fields[SPBuiltInFieldId.Title];

To change the display name on the main language (and depending on your settings force that down on all the other languages) set the Title attribute and call Update on the field:

field.Title = "My New Title";
field.Update();

To change the MUI version of the display name on a secondary language user TitleResource.SetValueForUICulture:

field.TitleResource.SetValueForUICulture(new CultureInfo("nb-NO"), "Local Title");
field.Update();

And to annoy everybody this only set the local display name for one of the three Title fields so you have to repeat it for the other two:

field = customersList.Fields[SPBuiltInFieldId.LinkTitle];
field.TitleResource.SetValueForUICulture(new CultureInfo("nb-NO"), "Local Title");
field.Update();
field = customersList.Fields[SPBuiltInFieldId.LinkTitleNoMenu];
field.TitleResource.SetValueForUICulture(new CultureInfo("nb-NO"), "Local Title");
field.Update();

So the total sequence may be something like:

var field = customersList.Fields[SPBuiltInFieldId.Title];
field.Title = "My New Title";
var culture = new CultureInfo("nb-NO");
field.TitleResource.SetValueForUICulture(culture, "Local Title");
field.Update();

field = customersList.Fields[SPBuiltInFieldId.LinkTitle];
field.TitleResource.SetValueForUICulture(culture, "Local Title");
field.Update();

field = customersList.Fields[SPBuiltInFieldId.LinkTitleNoMenu];
field.TitleResource.SetValueForUICulture(culture, "Local Title");
field.Update();
1
  • Thanks very much. This is exactly the sort of info I was looking for. For some reason, though, the field just seems to stubbornly refuse updating. I can see the changes reflected in the object model, but there are still no traces on the List Settings page. Might just be something weird with my test farm. May 14, 2012 at 11:58
2

Are you trying to change the display name property of the field? Note that InternalName, display name and StaticName are all different properties of the field. And the display name property is actually called Title.

customersList.Fields["Title"].Title = "Firma";
customersList.Fields["Title"].Update();
3
  • I am trying to change the display name. As I said above, the property has a different name in the Norwegian site template, so your code causes a runtime exception: i.imgur.com/jEguA.png. I was also under the impression that changing the InternalName or StaticName of the Title field was bad practice. Would it resolve my problem? Although come to think of it, SharePoint still indicates that the internal name of the field is "Title". So I don't see WHY your code should fail. [Exception translation: Cannot find field with name "Title"] May 11, 2012 at 7:09
  • Since this whole thing seems pretty confusing, it's also worth mentioning that the debugger in fact verifies that the DisplayName has been updated. Both titleField.TitleResource.Value and titleField.Title are in fact "Firma" when my code is finished executing. There are just no traces of this in the web interface. May 11, 2012 at 7:41
  • You can try these 1. Calculated column 2. Simple Sharepoint Designer Workflow 3. Item Added Event handler
    – neo269
    May 12, 2012 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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