2

How do you programmatically enable Enterprise Keywords for a SharePoint 2010 list?

This is how you do it using the GUI:

Enterprise Keywords enabler http://img248.imageshack.us/img248/2532/enterpisskeycrap.png

Igor Philippov has a solution which uses reflection and adds the field to the items in the library but doesn't fully work - it doesn't show the Enterprise Keywords field when viewing/editing properties, and it doesn't check this checkbox. I'm not sure why, since it seems to do the exact same thing as the code-behind for the checkbox in the GUI (in Microsoft.SharePoint.Taxonomy.OM.CodeBehind.MetadataColSettings.OkButton_Click).

Specifically, when enabling Enterprise Keywords via the GUI, it seems that the Enterprise Keywords field is added to all the list's content types, but when doing it programmatically this way, the field is only added to the default content type.

Another solution is to simply add the Enterprise Keywords column to the list, but that has exactly the same drawbacks, right?

1

The key here is to know the secret number, i.e. the Guid of the Keyword Metadata field, which is:

23F27201-BEE3-471e-B2E7-B64FD8B7CA38

For collectors, here is a list of SharePoint 2010 Guids.

Then I think you can solve the problem, e.g.:

<FieldRef ID="{23f27201-bee3-471e-b2e7-b64fd8b7ca38}" Name="TaxKeyword" />

I think to do it programmatically you would do something like:

SPField field = this.m_list.ParentWeb.AvailableFields[guid];
list.Fields.Add(field);

Disclaimer: I haven't tested this, sorry.

0

You can even add enterprise keywords column to your list using reflection. See my question here on sharepointoverflow.

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.