Reputation: 21778
Everybody loves renaming columns. The title column is a favorite of mine and I can't seem to rename it via code:
SPList list = web.Lists.TryGetList("MyList");
Guid guid = new Guid("fa564e0f-0c70-4ab9-b863-0177e6ddd247"); //Title column
SPField field = list.Fields[guid];
field.Title = "Testing";
field.Update();
list.Update();
The title column always stays the title column (the DisplayName
at least). Of course I don't want to rename the InternalName
or anything crazy, but since you can't remove the column it would be nice if it actually had a meaningful name in my SP context.
So the question in short: How to rename the title column/field in a document library using code (that means C# - not XML)?"
PS: Of course it works via the UI. Go to document library settings > Columns > Title and you can change the name to your liking (this is updated on all views then)
SchemaXML
:
string schema = field.SchemaXML;
schema.Replace("Title", "NewNameHere");
field.SchemaXml = schema;
field.Update();
list.Update();
Still the field's display name is "Title.
Upvotes: 3
Views: 2533
Reputation: 21778
Localization is the issue. I need to change the TitleResource
additional to the Title
:
field.TitleResource.SetValueForUICulture(new CultureInfo(1033), "My title");
As explained here.
Upvotes: 3