Sometimes we have a requirement where we need to create the content type in hub and publish the same via code. Following are the methods to Publish or Un-Publish the Content Type in Content Type HUB
public static String PublishorUnPublishedContentType(SPSite hubSiteCollection, SPContentType cType, bool doPublish)
{
String sMessage = String.Empty;
if (ContentTypePublisher.IsContentTypeSharingEnabled(hubSiteCollection))
{
ContentTypePublisher publisher = new ContentTypePublisher(hubSiteCollection);
try
{
if (doPublish)
{
publisher.Publish(cType);
sMessage = "Content Type Published Successfully.";
}
else
{
if (publisher.IsPublished(cType))
{
publisher.Unpublish(cType);
sMessage = "Content Type UnPublished Successfully.";
}
else
{
sMessage = "Content Type is not published. You need to Publish the Content Type before UnPublished.";
}
}
}
catch (Exception ex)
{
sMessage = ex.Message;
}
}
else
{
// The provided site is not a valid hub site.
sMessage = hubSiteCollection.Url + ": is not a valid Content Hub Site.";
}
return sMessage;
}
Hope this will help you out !!!!!
No comments:
Post a Comment