Skip to main content
Code formatting
Source Link
P S
  • 4.8k
  • 4
  • 28
  • 50

There are couple options you can try.

  1. youYou can call TermSet.GetAllTerms()TermSet.GetAllTerms() method to return all terms under that TermSet.
  2. anotherAnother approach you can try is to use recursive function to enumerate termSet.TermstermSet.Terms and term.Termsterm.Terms

I list the code for approach 1 at the following. youYou can check term.PathOfTermterm.PathOfTerm to find out the term's hierarchy information.

    class Program
    {
    static void Main(string[] args)
    {
        Test();
    }
    private static void Test()
    {
        string url = "http://sp1:1111";
        using (ClientContext context = new ClientContext(url))
        {
            TaxonomySession session = TaxonomySession.GetTaxonomySession(context);
            TermStore store = session.GetDefaultSiteCollectionTermStore();
            TermSet termSet = store.GetTermSet(new Guid("6e17ec6e-7456-4e61-82e9-d5a75f6932fa"));
            TermCollection terms = termSet.GetAllTerms();
            context.Load(terms);
            context.ExecuteQuery();
            foreach(Term term in terms)
            {
                Console.WriteLine(term.PathOfTerm);
            }
            Console.WriteLine();
        }
    }
}

There are couple options you can try.

  1. you can call TermSet.GetAllTerms() method to return all terms under that TermSet.
  2. another approach you can try is to use recursive function to enumerate termSet.Terms and term.Terms

I list the code for approach 1 at the following. you can check term.PathOfTerm to find out the term's hierarchy information.

    class Program
    {
    static void Main(string[] args)
    {
        Test();
    }
    private static void Test()
    {
        string url = "http://sp1:1111";
        using (ClientContext context = new ClientContext(url))
        {
            TaxonomySession session = TaxonomySession.GetTaxonomySession(context);
            TermStore store = session.GetDefaultSiteCollectionTermStore();
            TermSet termSet = store.GetTermSet(new Guid("6e17ec6e-7456-4e61-82e9-d5a75f6932fa"));
            TermCollection terms = termSet.GetAllTerms();
            context.Load(terms);
            context.ExecuteQuery();
            foreach(Term term in terms)
            {
                Console.WriteLine(term.PathOfTerm);
            }
            Console.WriteLine();
        }
    }
}

There are couple options you can try.

  1. You can call TermSet.GetAllTerms() method to return all terms under that TermSet.
  2. Another approach you can try is to use recursive function to enumerate termSet.Terms and term.Terms

I list the code for approach 1 at the following. You can check term.PathOfTerm to find out the term's hierarchy information.

    class Program
    {
    static void Main(string[] args)
    {
        Test();
    }
    private static void Test()
    {
        string url = "http://sp1:1111";
        using (ClientContext context = new ClientContext(url))
        {
            TaxonomySession session = TaxonomySession.GetTaxonomySession(context);
            TermStore store = session.GetDefaultSiteCollectionTermStore();
            TermSet termSet = store.GetTermSet(new Guid("6e17ec6e-7456-4e61-82e9-d5a75f6932fa"));
            TermCollection terms = termSet.GetAllTerms();
            context.Load(terms);
            context.ExecuteQuery();
            foreach(Term term in terms)
            {
                Console.WriteLine(term.PathOfTerm);
            }
            Console.WriteLine();
        }
    }
}
Source Link

There are couple options you can try.

  1. you can call TermSet.GetAllTerms() method to return all terms under that TermSet.
  2. another approach you can try is to use recursive function to enumerate termSet.Terms and term.Terms

I list the code for approach 1 at the following. you can check term.PathOfTerm to find out the term's hierarchy information.

    class Program
    {
    static void Main(string[] args)
    {
        Test();
    }
    private static void Test()
    {
        string url = "http://sp1:1111";
        using (ClientContext context = new ClientContext(url))
        {
            TaxonomySession session = TaxonomySession.GetTaxonomySession(context);
            TermStore store = session.GetDefaultSiteCollectionTermStore();
            TermSet termSet = store.GetTermSet(new Guid("6e17ec6e-7456-4e61-82e9-d5a75f6932fa"));
            TermCollection terms = termSet.GetAllTerms();
            context.Load(terms);
            context.ExecuteQuery();
            foreach(Term term in terms)
            {
                Console.WriteLine(term.PathOfTerm);
            }
            Console.WriteLine();
        }
    }
}