Sunday 21 June 2015

Programmatically Create a Term Group if not exist in SharePoint 2013 Online Term Store Management


It is possible to programmatically create a term group  if not exist in SharePoint 2013 Online Term Store Management. The following method illustrates the steps:



public static Microsoft.SharePoint.Client.Taxonomy.TermGroup CreateTermGroupIfNotExist(ClientContext context, TermStore parent, Guid termGroupId, string termGroupName, string termGroupDescription = null)
        {
            Microsoft.SharePoint.Client.Taxonomy.TermGroup termGroup = null;
            try
            {
                context.Load(parent, ts => ts.Groups);
                termGroup = parent.GetGroup(termGroupId);
                context.Load(termGroup, ts => ts.Id);
                context.ExecuteQuery();

                if (termGroup.ServerObjectIsNull != null && termGroup.ServerObjectIsNull.Value)
                {
                    parent.CreateTermGroup(termGroupName, termGroupId, termGroupDescription);
                    context.ExecuteQuery();
                }
            }
            catch (Exception ex)
            {
               
                throw ex;
            }
            return termGroup;
        }

The above method will create a term group by the name termGroupName with the id termGroupId and description termGroupDescription.


Happy SharePointing.........:)

2 comments:

  1. Wonderful post however I was wondering if you could write a little more on this SharePoint topic? I’d be very thankful if you could elaborate a little bit further. Thank you!
    SharePoint Administrator Online Training

    ReplyDelete
  2. @Manideep Agarwal.....I'll try to follow your suggestions in next posts.

    ReplyDelete