In this article we will be seeing how to check whether the site is a valid hub site and how to check whether the content type in the hub site is published or not. Steps Involved:
Using console application:
C# Code snippet: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Taxonomy.ContentTypeSync;
namespace EMM { class Program { static void Main(string[] args) { using (SPSite site = new SPSite("http://servername:20/")) { using (SPWeb web = site.RootWeb) { SPContentType contentType = web.ContentTypes["_bContentType"]; if (ContentTypePublisher.IsContentTypeSharingEnabled(site)) { Console.WriteLine(site.Url.ToString() + " is a valid hub site"); ContentTypePublisher ctPublisher = new ContentTypePublisher(site); if (ctPublisher.IsPublished(contentType)) { Console.WriteLine(contentType.Name + " is published content type"); } else { Console.WriteLine(contentType.Name + " is unpublished content type"); } } else { Console.WriteLine(site.Url.ToString() + " is not a valid hub site"); } Console.ReadLine(); } } } } }
Powershell script: $hubSite=Get-SPSite "http://servername:10/" $hubWeb=$hubSite.RootWeb if([Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher]::IsContentTypeSharingEnabled($hubSite)) { write-host $hubSite.Url " is a valid hub site" $contentType=$hubWeb.ContentTypes["_bContentType"] $ctPublisher=New-Object Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher($hubSite) if($ctPublisher.IsPublished($contentType)) { write-host $contentType.Name "is published content type" } else { write-host $contentType.Name "is unpublished content type" } } else { write-host $hubSite.Url " is not a valid hub site" }
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: