This version adds the ability to add/retrieve Managers and Contributors to a Term Group in the SharePoint Online Term Store.
Here is a quick code snippet I put together for achieving this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ClientContext clientContext = GetClientContext(); | |
var taxonomySession = TaxonomySession.GetTaxonomySession(clientContext); | |
var termStore = taxonomySession.GetDefaultSiteCollectionTermStore(); | |
var myTermGroup = termStore.Groups.GetByName("My Custom Terms Group"); | |
//Add Group Managers | |
myTermGroup.AddGroupManager("i:0#.f|membership|ccdev2@tenant.onmicrosoft.com"); | |
//Add Group Contributors | |
myTermGroup.AddContributor("i:0#.f|membership|ccdev1@tenant.onmicrosoft.com"); | |
myTermGroup.AddContributor("i:0#.f|membership|ccdev3@tenant.onmicrosoft.com"); | |
clientContext.Load(myTermGroup, group => group.GroupManagerPrincipalNames, group => group.ContributorPrincipalNames); | |
clientContext.ExecuteQuery(); | |
Console.WriteLine("Group Managers: "); | |
foreach (var manager in myTermGroup.GroupManagerPrincipalNames) | |
{ | |
Console.WriteLine(manager); | |
} | |
Console.WriteLine("Group Contributors: "); | |
foreach (var contributors in myTermGroup.ContributorPrincipalNames) | |
{ | |
Console.WriteLine(contributors); | |
} |
Once executed, you can see that the Term Group in the Term Store is updated:
No comments:
Post a Comment