Monday, 13 March 2017

CSOM TermStore GetTerms

CSOM Get Groups in TermStore/CSOM Get Termsets in TermStore/ CSOM Get Terms in TermSets
















OutPut :






















using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;

namespace TermstoreCSOM
{
    class Program
    {
        static void Main(string[] args)
        {
            ClientContext ctx = new ClientContext("http://SPDev2013:3636/");
            ctx.Credentials = new System.Net.NetworkCredential("username", "pwd","domain");

            //Get the Taxanomy Session

            TaxonomySession tx = TaxonomySession.GetTaxonomySession(ctx);
            ctx.Load(tx, t => t.TermStores);
            ctx.ExecuteQuery();
           
            //Get the defualt TermStore from Taxonamy Session

            var ts = tx.TermStores[0];
            ctx.Load(ts);
            ctx.ExecuteQuery();
            Console.ForegroundColor = ConsoleColor.White;
           
            //Print the TermStore Name

            Console.WriteLine(ts.Name);

           //Get the Groups inside the Termstore

            TermGroupCollection groups = ts.Groups;
            ctx.Load(groups);
            ctx.ExecuteQuery();
            foreach( TermGroup group in groups)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
               
                //Print Each Group inside the TermStore

                Console.WriteLine("TermGroup is :" +group.Name);
               
                //Ge the Termsets inside the Each Group

                TermSetCollection termsetcollections = group.TermSets;
                ctx.Load(termsetcollections);
                ctx.ExecuteQuery();

                foreach (TermSet t in termsetcollections)
                {
                    Console.ForegroundColor = ConsoleColor.Green;

                    //Print Each Termset

                    Console.WriteLine("TermsetName is :" + t.Name);
                    ctx.Load(t);
                    ctx.Load(t.GetAllTerms());
                    ctx.ExecuteQuery();
                   
                    //Get All the Terms inside the TermSet

                    TermCollection terms = t.GetAllTerms();
                    ctx.Load(terms);
                    ctx.ExecuteQuery();
                    foreach (Term term in terms)
                    {
                       
                      Console.ForegroundColor = ConsoleColor.DarkCyan;
                          
                        //Print Each Term inside TermSet
                         
                        Console.WriteLine("Terms is :" + term.Name);

                    }

                }

            }
            Console.ReadKey();

           

        }
    }
}


1 comment:

  1. 1xbet korean casino | Deposit bonus codes | bet365 legalbet
    1xbet korean casino. Bet365 has always had the best 인카지노 casino software 바카라사이트 and we are always happy to 1xbet help you win your share of profits.

    ReplyDelete