PnP Core Component - Get a taxonomy term by name in SharePoint 2016

Please refer to the Introduction to PnP Core Component and OfficeDevPnP.Core for more details. I have created a console application and added SharePointPnPCore2016 NuGet package for the SharePoint 2016 version.
 
Code Snippet
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using Microsoft.SharePoint.Client;  
  7. using OfficeDevPnP.Core;  
  8. using OfficeDevPnP.Core.Extensions;  
  9. using Microsoft.SharePoint.Client.Taxonomy;  
  10.   
  11. namespace SP2016PnPCoreComponentDemo  
  12. {  
  13.     class Program  
  14.     {  
  15.         static void Main(string[] args)  
  16.         {  
  17.             // Input Parameters    
  18.             string siteUrl = "http://c7395723754/";  
  19.             string userName = "administrator";  
  20.             string password = "Mf165Nz2WV";  
  21.             string domain = "AD2012";  
  22.             Guid termSetID = new Guid("e6b07ab0-99d2-42b7-b2c7-ab6cdadf216d");  
  23.             string termName = "PnP Create Group";  
  24.   
  25.             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();  
  26.   
  27.             try  
  28.             {  
  29.                 // Get the client context    
  30.                 using (var ctx = authMgr.GetNetworkCredentialAuthenticatedContext(siteUrl, userName, password, domain))  
  31.                 {  
  32.                     // Get a Taxonomy Term by Name  
  33.                     Term term = ctx.Site.GetTermByName(termSetID, termName);  
  34.                     Console.WriteLine(term.Description);  
  35.                     Console.ReadLine();  
  36.                 }  
  37.             }  
  38.   
  39.             catch (Exception ex)  
  40.             {  
  41.                 Console.WriteLine("Error Message: " + ex.Message);  
  42.             }  
  43.         }  
  44.     }  
  45. }  
 
Ebook Download
View all
Learn
View all