There are couple options you can try.
- youYou can call TermSet.GetAllTerms()
TermSet.GetAllTerms()
method to return all terms under that TermSet. - anotherAnother approach you can try is to use recursive function to enumerate termSet.Terms
termSet.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();
}
}
}