Monday 22 December 2014

Create a Term Set and Terms in SharePoint 2010 Programatically

Created a Term Set in Managed Metadata Service Application then I can create a custom term set and terms using TaxonomyWebTaggingControl object is a Web control that can be added to a page so that a user can pick one or more taxonomy Term object from a specific TermSet object or from an entire TermStore object."
  1. //add new term set into manage data    
  2. using (SPSite site = new SPSite(SPContext.Current.Site.Url))    
  3. {    
  4.        TaxonomySession _TaxonomySession = new TaxonomySession(site);    
  5.     
  6.        //Get instance of the Term Store     
  7.        TermStore _TermStore = _TaxonomySession.TermStores[0];    
  8.     
  9.        //Now create a new Term Group    
  10.        Group _Group = _TermStore.CreateGroup("MyGroup");    
  11.     
  12.        //Create a new Term Set in the new Group    
  13.        TermSet _TermSet = _Group.CreateTermSet("MyTermset");    
  14.     
  15.        //Add terms to the term set    
  16.        Term _term1 = _TermSet.CreateTerm("A Term", 1033);    
  17.        Term _term2 = _TermSet.CreateTerm("B Term", 1033);    
  18.        Term _term3 = _TermSet.CreateTerm("C Term", 1033);    
  19.        Term _term4 = _TermSet.CreateTerm("D Term", 1033);    
  20.     
  21.        //commit changes    
  22.        TermStore.CommitAll();    
  23.     
  24. }   

Convert a SharePoint WebApplication from Classic authentication to Claims

Here is a quick Powershell script to convert a SharePoint WebApplication from Classic (Windows) Authentication to Claims Authentication. This script is tested in SharePoint 2010 only.

When working with SharePoint 2013, you will not need this in most cases as the default authentication provider is Claims.

1234567891011121314
$WebAppName = "http://webappurl/"
$wa = get-SPWebApplication $WebAppName
$wa.UseClaimsAuthentication = $true
$wa.Update()
$account = "domain\username"
$account = (New-SPClaimsPrincipal -identity $account -identitytype 1).ToEncodedString()
$wa = get-SPWebApplication $WebAppName
$zp = $wa.ZonePolicies("Default")
$p = $zp.Add($account,"PSPolicy")
$fc=$wa.PolicyRoles.GetSpecialRole("FullControl")
$p.PolicyRoleBindings.Add($fc)
$wa.Update()
$wa.MigrateUsers($true)
$wa.ProvisionGlobally()

No comments:

Post a Comment