Thursday, July 14, 2011

Push changes from the SharePoint Content hub to a SiteCollection

When working with the Content hub, you may need the content type you just added to the hub, to be pushed out to a specific site collection immediately. This can be done by activating the timer jobs specified here, or you can just force an activation of the Feature “TaxonomyFieldAdded” on the target SiteCollection.

The TaxonomyFieldAdded feature is a site scoped and hidden feature, its job is to enable the site as Content hub receiver and sync up with the hub immediately. Therefore a reactivation of the feature will get the latest changes from the Content hub, and do not take a lot of time waiting for the timer jobs to finish.

PowerShell:

Enable-SPFeature "TaxonomyFieldAdded" -url "http://mydomain/mySiteCollection/" –force

Code: C#

//The FeatureDefinition id of “TaxonomyFieldAdded” is "73ef14b1-13a9-416b-a9b5-ececa2b0604c". The last “true” is for “Force” feature activation.

site.Features.Add(
new Guid("73ef14b1-13a9-416b-a9b5-ececa2b0604c"), true);

 

So this enables the scenario where you can create a Site Feature Receiver that will publish a content type on the content hub, then force the sync to the local site collection and create a list that uses the content type. All within the same receiver and only takes a couple of seconds to execute.