none
Update TAXONOMY TERM STORE, managed Metadata Service RRS feed

  • Question

  • I am in a process of building a tree view of managed meta data of taxonomy.

    I want to build a group with a description  and sort specified as parmeters by searching by guid id.
    If the group is not there create it or get the grp by guid and update description and sort.
    I then want to create a term set under that group above created/modified and again search by guid and modify the description and sort and then finally create/modify the term under that termset and again search by guid.

    I want to re run the script so if term sets are built just override it with values of description and sort.
    I am not sure or i havent seen the code on the net but i am not sure whether to delete the groups and everything under it.
    I would like this in c# and really appreciated on this.

    Thanks
    Sunday, April 16, 2017 4:24 PM

All replies

  • Hi,

    Here is the code snippet for your reference, you could try with it and post detail issue if any.

    https://msdn.microsoft.com/en-us/library/office/jj163949.aspx?f=255&MSPPError=-2147217396

     private void CreateColorsTermSet(string siteUrl)
            {
               ClientContext clientContext = new ClientContext(siteUrl);
     
               TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
                clientContext.Load(taxonomySession,
                    ts => ts.TermStores.Include(
                        store => store.Name,
                        store => store.Groups.Include(
                            group => group.Name
                            )
                        )
                    );
                clientContext.ExecuteQuery();
     
               if( taxonomySession != null )
                {
                   TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
                   if (termStore != null)
                    {
                       //
                       //  Create group, termset, and terms.
                       //
                       TermGroup myGroup = termStore.CreateGroup("MyGroup",Guid.NewGuid());
                       TermSet myTermSet = myGroup.CreateTermSet("Color",Guid.NewGuid(), 1033);
                        myTermSet.CreateTerm("Red", 1033,Guid.NewGuid());
                        myTermSet.CreateTerm("Orange", 1033,Guid.NewGuid());
                        myTermSet.CreateTerm("Yellow", 1033,Guid.NewGuid());
                        myTermSet.CreateTerm("Green", 1033,Guid.NewGuid());
                        myTermSet.CreateTerm("Blue", 1033,Guid.NewGuid());
                        myTermSet.CreateTerm("Purple", 1033,Guid.NewGuid());
     
                        clientContext.ExecuteQuery();
                    }
                }
            }
     
           private void DumpTaxonomyItems(string siteUrl)
            {
               ClientContext clientContext = new ClientContext(siteUrl);
     
               //
               // Load up the taxonomy item names.
               //
                TaxonomySession taxonomySession =TaxonomySession.GetTaxonomySession(clientContext);
               TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
                clientContext.Load(termStore,
                        store => store.Name,
                        store => store.Groups.Include(
                            group => group.Name,
                            group => group.TermSets.Include(
                                termSet => termSet.Name,
                                termSet => termSet.Terms.Include(
                                    term => term.Name)
                            )
                        )
                );
                clientContext.ExecuteQuery();
     
     
               //
               //Writes the taxonomy item names.
               //
               if( taxonomySession != null )
                {
                   if (termStore != null)
                    {
                       foreach( TermGroup groupin termStore.Groups)
                        {
                           Console.WriteLine("Group " + group.Name);
     
                           foreach( TermSet termSetin group.TermSets )
                            {
                               Console.WriteLine("TermSet " + termSet.Name);
     
                                foreach(Term term in termSet.Terms)
                                {
                                   //Writes root-level terms only.
                                   Console.WriteLine("Term " + term.Name);
                                }
                            }
                        }
                    }
                }
     
            }

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, April 17, 2017 1:47 AM
  • Hi,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    You can mark the helpful post as answer to help other community members find the helpful information quickly.

    You can also share your own solution here and mark it as answer, so it may help others who has similar requirement.

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, May 4, 2017 8:27 AM