Getting the URL to the Content Type Hub Programmatically in SharePoint 2010

Many organizations use the content-type hub to manage content-types in their SharePoint 2010 environment.  As a developer in these types of organizations, you may one day find yourself in need of getting the URL of the content type hub programmatically.  Here is a quick snippet that demonstrates how to do it fairly painlessly:

public static Uri GetContentTypeHubUri(SPSite site)
{
    TaxonomySession session = new TaxonomySession(site);
    return Session.
DefaultSiteCollectionTermStore
       
.ContentTypePublishingHub;
}

  • 3511 views

  • Rate
    [Total: 0    Average: 0/5]