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

Does anyone know of a way to lock down a list's built in Enterprise Keyword field to a specific Term Set? I've found on similar solution, but that solution only created a new Site Column that allowed a mult-select Taxonomy field and allowed users to add to the Taxonomy. On the other hand, I'm looking for a way to assist users in selecting keywords while still allowing them to tag enterprise keywords that will not be added to my Managed Metadata. In trying to come up with a proof of concept, I think I created a pretty good example:

public class Feature1EventReceiver : SPFeatureReceiver
{
    private Guid _termSetID = new Guid("4ec3eb26-fb69-49d6-9143-dc41f976443f");
    private Guid _gamesListID = new Guid("d7e1ce12-9523-47df-8ed3-5c4af9e2ee88");
    private Guid _fieldListID = new Guid("23f27201-bee3-471e-b2e7-b64fd8b7ca38");

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        try
        {
            using(var site = (SPSite)properties.Feature.Parent)
            {
                TaxonomySession session = new TaxonomySession(site);
                TermStore termStore = session.TermStores["Managed Metadata Service"];
                Group group = termStore.Groups["Video Games"];
                TermSet termSet = group.TermSets["Xbox"];

                using(var web = site.RootWeb)
                {
                    SPList list = web.Lists[_gamesListID];
                    TaxonomyField field = (TaxonomyField)list.Fields[_fieldListID];
                    field.TermSetId = _termSetID;
                    //field.TermSetId = termSet.Id;
                    //field.IsKeyword = false;
                    field.CreateValuesInEditForm = true;
                    field.Title = "Xbox Enterprise Keywords";
                    field.Update();
                    list.Update();
                }
            }
        }
        catch (Exception)
        {
            throw;
        }
    }

}

In this case, I could create a list item Halo 4. I may want to mark it Halo and Microsoft Game Studios from my Xbox term set that lives in my Video Games term store. I also would want to create an enterprise keyword for Sequel or 4, but not add those to my Xbox term set, or my Video Games term store at all. However with the way Sharepoint 2010 OOTB works, it's all or nothing. If I type in 'Mar' into my Enterprise Keywords field, I will get an auto suggestion for Mario from my Nintendo term set, which obviously isn't the desired result.

The odd thing is I can run the code no error, but the change doesn't persist.

share|improve this question

1 Answer 1

the enterprise keywords field cannot be limited to one term set. This can only be done if you have multiple term stores to seperate them. What you need to do is create a new taxonomy field for your list/site collection and set the desired term set to this field like so:

field.SspId = termStore.Id;
field.TermSetId = termSet.Id;
field.PushChangesToLists = true;
field.Update();

Hope this helps you in any way...

share|improve this answer

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.