How to Check If the Taxonomy Group is a Site Collection Group using CSOM in SharePoint 2013

Navigate to the site collection http://c4968397007/. Click on Settings, and then click on Site Settings. Click on Term store management which is available under Site Administration section. You could be able to see all the groups in the Taxonomy Term Store. In this blog you will see how to check if the group is a site collection group using client side object model in SharePoint 2013.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Collections.ObjectModel;

using Microsoft.SharePoint.Client;

using Microsoft.SharePoint.Client.Taxonomy;

namespace TaxonomyCodeSamples

{

    class Program

    {

        static void Main(string[] args)

        {

            // ClienContext - Get the context for the SharePoint Site

            // SharePoint site URL - http://c4968397007/

            ClientContext clientContext = new ClientContext("http://c4968397007/");

            // Get the TaxonomySession

            TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);

            // Get the term store by name

            TermStore termStore = taxonomySession.TermStores.GetByName("MMS");

            clientContext.Load(termStore.Groups);

            clientContext.ExecuteQuery();

            // Loop through all the groups in the termstore

            foreach (TermGroup termGroup in termStore.Groups)

            {

                // Check if the group is a site collection group

                if (termGroup.IsSiteCollectionGroup)

                {

                    // Display the name of the site collection group

                    Console.WriteLine(termGroup.Name + " is a site collection group");

                }

            }

            Console.ReadLine();

        }

    }

}

 

 




 

Ebook Download
View all
Learn
View all