Question

I have created managed metadata Group named "MyGroup" in term store (Managed Metadata Service) programmatically under FeatureActivated method in SharePoint 2013 as below:

     public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {

        Guid fieldID1 = new Guid("{e7344bac-ce09-4254-96eb-387aa0635bd4}");
        SPSite site = properties.Feature.Parent as SPSite;
        TaxonomySession session = new TaxonomySession(site);
        var termStore = session.TermStores["Managed Metadata Service"]; 

            var group = termStore.CreateGroup("MyGroup");
            SPField field1 = site.RootWeb.Fields[fieldID1];
            var termSet1 = group.CreateTermSet(field1.InternalName);
    // Connect to MMS
  TaxonomyField taxonomyField1 = site.RootWeb.Fields[fieldID1] as TaxonomyField;
     taxonomyField1.SspId = termSet1.TermStore.Id;
                            taxonomyField1.TermSetId = termSet1.Id;
                            taxonomyField1.TargetTemplate = string.Empty;
                            taxonomyField1.AnchorId = Guid.Empty;
                            taxonomyField1.Update();
        }

Code successfully executed but I don't see "MyGroup" under site settings->Term store management. Why its not there ?

Was it helpful?

Solution

I think you are missing the CommitAll() after you make the changes to the termstore.

...
var termSet1 = group.CreateTermSet(field1.InternalName);
termStore.CommitAll();
...

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.taxonomy.termstore.commitall.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top