Tuesday 24 April 2012

Sharing A Site Collection Term Store Among Multiple Site Collections

Site collection term stores are just special groups (IsSiteCollectionGroup = true) in an MMS term store (TaxonomySession.DefaultSiteCollectionTermStore). By default there is a one to one mapping between a site collection and the associated group, but in theory a group can be accessed by multiple site collections, and a site collection can only have one such group.

For each site collection, the root web o contains a property key in the form of SiteCollectionGroupId{Guid}, i.e. SiteCollectionGroupId75e2d28e-01ce-4100-b130-7898bed9ad24, the value of this property is the id of the corresponding group in the term store which serves as the "site collection term store" for this site collection.

Each group has a property called SiteCollectionAccessIds that contains a list of site collection IDs of which has access to this group; by default it only contains a single value.

Once you understand the information above, it is not difficult to achieve sharing a group among multiple site collections. Let’s say you have site collection SiteA and SiteB and you want them to share the same site collection term store, follow the steps below:
  1. Identify the site collection group SiteA is currently using. This can be done by examine SiteA.RootWeb.AllProperties and look for the key SiteCollectionGroupId{Guid}, mark down the value.
  2. Locate the site collection group based on the id retrieved from step 1 above, and then add SiteB.ID to this group’s SiteCollectionAccessIds.
  3. Point SiteB to the group identified in step 2. This can be done by modifying SiteB.RootWeb.AllProperties["SiteCollectionGroupId{Guid}"]with the group id retrieved from step 1.
You are done!

Inspired by the link below:
Restore a link between a site collection and a local term store group after restoring site collection from backup.