none
Get Child Items from Term set c#

    Question

  • Our navigation is term driven... and I can use the following method to get the term items for each section.

    It returns something like this

    Parent

    Parent

    Parent

    What I need is 

    Parent

      child
      child
          child

    Parent

     child
      child
          child

    Parent

    I have this method which gives me the parent but I cannot seem to get the child.

     public static void GetTermSetData()
            {
                ClientContext clientContext = new ClientContext("https://cloud.sharepoint.com/sites/mydeveloper/");
                SecureString passWord = new SecureString();
                foreach (char c in "XXXXXX".ToCharArray()) passWord.AppendChar(c);
                clientContext.Credentials = new SharePointOnlineCredentials("email address", passWord);
                // Get the TaxonomySession
                TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
    
                // Get the term store by name
                TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
    
                // Get the term group by Name
                TermGroup termGroup = termStore.Groups.GetByName("Site Collection - cloud.sharepoint.com-sites-mydeveloper");
    
                // Get the term set by Name
                TermSet termSet = termGroup.TermSets.GetByName("Primary Navigation");
    
                // Get all the terms 
                TermCollection termColl = termSet.Terms;
    
                clientContext.Load(termColl);
    
                // Execute the query to the server
                clientContext.ExecuteQuery();
    
                // Loop through all the terms
                foreach (Term term in termColl)
                {
                    // Display the term name
                    Console.WriteLine(term.Name);
    
                }
    
                Console.ReadLine();
            }

    Any help is appreciated.


    sayitfast

    Tuesday, April 26, 2016 4:50 PM

Answers