Setting the Title field for Content Types

This is one I’ve been meaning to blog about for a while. I was using a Content Type where I was trying to set the display name of ‘Title’ field. I was happy to have a Title column, but I wanted it to have a different name.

I tried doing this declaratively:

<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Request" Required="FALSE" />

However, I found this didn’t work in SP2010 – the field still appeared as ‘Title’. This was frustrating.

Instead, I had to set the Title’s display name in code:

foreach (SPFieldLink fldLnk in contentType.FieldLinks)
{
if (fldLnk.Id == SPBuiltInFieldId.Title)
{
fldLnk.DisplayName = "Request";
}
}
contentType.Update(false);

This was a bit strange – other fields can have a DisplayName set in CAML quite happily. This seems to just be a feature of the Title column.

EDIT: I also had to use a similar approach on setting the Title column for a content type used on a list – but using:

private void SetTitleField(SPWeb web, string listname, string contentTypeName, string newTitleName)
{
SPList list = web.Lists[listname];
SPContentType ct = list.ContentTypes[contentTypeName];

foreach (SPFieldLink fldLnk in ct.FieldLinks)
{
//Necessary to set title field - when using content types, this seems to set it to "Title" irrespective of what is set in the Content type or list's XML.
if (fldLnk.Id == SPBuiltInFieldId.Title)
{
	fldLnk.DisplayName = newTitleName;
	ct.Update(false);
	break;
}
}
foreach (SPField fld in list.Fields)
{
if (fld.Id == SPBuiltInFieldId.Title)
{
	fld.Title = newTitleName;
	fld.Update();
	break;
}
}
}
Setting the Title field for Content Types

4 thoughts on “Setting the Title field for Content Types

  1. Beware changing the “Title” column in content types. There are some hidden nasties about doing this. We found that users who changed the title column on our content type on their own websites found that when we made a push from the syndication hub, their column reverted to “Title”. This made them unhappy and confused, because now they could’t find their “Requestor” field anymore. Because “Title” is the only required field (besides the system fields like “Modified by”), it really shouldn’t be messed with. If you are a site owner, and the farm content type has title, and you don’t like it, ask the admins if they will hide it for you. If you are the admins, and you don’t want title in your content type, hide it. I have just seen too many situations go to pot because someone messed with a content type and they didn’t know what they were doing, didn’t realize that the content type was farm-wide, or didn’t realize that Title was a required (as in can’t get rid of it, not as in you can’t change it so that you don’t have to fill it). I even had someone try to delete the column. We had to restore their library.

    Like

  2. Hi Rebecca, well, that’s good to know. I’ve gotta confess, I’ve never had any problems with renaming it, but then I’ve never tried pushing the Content Type into other Site Collections – so either publishing it, or using the Enterprise Content Type Hub.

    The unfortunate thing about simply hiding the Title column is that it has (in one of it’s forms) the item menu attached to it. It’d be a shame to lose that sometimes. I guess that might be less of an issue in a publishing scenario.

    But I’ll keep your discoveries in mind!

    Like

  3. Heath says:

    Andy, if the item menu is your only concern with hiding the Title column, can’t you just add a ListItemMenu=”TRUE” to your CAML declaration in the view?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s