ContentTypePublisher classe
Publica ou cancela a publicação de um tipo de conteúdo no site do hub.
Inheritance hierarchy
System.Object
Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher
Namespace: Microsoft.SharePoint.Taxonomy.ContentTypeSync
Assembly: Microsoft.SharePoint.Taxonomy (em Microsoft.SharePoint.Taxonomy.dll)
Sintaxe
'Declaração
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class ContentTypePublisher
'Uso
Dim instance As ContentTypePublisher
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class ContentTypePublisher
Comentários
Depois que um aplicativo de serviço de metadados gerenciados e de proxy são provisionados e um site tiver sido designado como o hub no aplicativo de serviço, use essa classe para publicar ou cancelar os tipos de conteúdo no site do hub.
Além disso, use essa classe para verificar se um tipo de conteúdo deste site de hub for publicado e verifique se o recurso de MetadataHub está habilitado no hub.
Exemplos
using System;
using System.IO;
using System.Globalization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
using Microsoft.SharePoint.Taxonomy.ContentTypeSync;
namespace Microsoft.SDK.SharePointServer.Samples
{
public static class ContentTypeSyndicationSamples
{
/// <summary>
/// Demostrates how to use ContentTypePublisher class by creating a new
/// content type and then publish it and unpublish it.
/// Before this method is called, a Managed Metadata service application
/// should be created and a hub has been designated on the service application.
/// </summary>
/// <param name="hubSite">
/// The site that has been designated as the hub
/// </param>
public static void UseContentTypePublisher(SPSite hubSite)
{
// Get the root web of the site
SPWeb rootWeb = hubSite.RootWeb;
// Create a new content type based on Document content type
SPContentType docCt = rootWeb.ContentTypes["Document"];
Random random = new Random();
string newCTName = "Test content type " + random.Next().ToString();
SPContentType newCt = new SPContentType(docCt,
rootWeb.ContentTypes,
newCTName);
rootWeb.ContentTypes.Add(newCt);
Console.WriteLine(newCTName + " has been created.");
// Check if the site is a valid hub site
if (ContentTypePublisher.IsContentTypeSharingEnabled(hubSite))
{
ContentTypePublisher publisher = new ContentTypePublisher(hubSite);
Console.WriteLine("Publishing the content type. ");
publisher.Publish(newCt);
// Check if this content type has been published
if (publisher.IsPublished(newCt))
{
Console.WriteLine(newCTName + " is a published content type.");
}
Console.WriteLine("Unpublishing the content type. ");
publisher.Unpublish(newCt);
// Check if this content type is still published
if (!publisher.IsPublished(newCt))
{
Console.WriteLine(newCTName + " is not a published content type.");
}
}
else
{
// The provided site is not a valid hub site
Console.WriteLine("This site is not a valid hub site");
}
}
}
}
Segurança de thread
Os membros públicos estática (Shared no Visual Basic) desse tipo são seguros para thread. Nenhum membro de instância pode ser garantido como seguro para thread.