Partager via


ContentTypePublisher - Classe

Publie ou annule sa publication d'un type de contenu sur le site du concentrateur.

Hiérarchie d’héritage

System.Object
  Microsoft.SharePoint.Taxonomy.ContentTypeSync.ContentTypePublisher

Espace de noms :  Microsoft.SharePoint.Taxonomy.ContentTypeSync
Assembly :  Microsoft.SharePoint.Taxonomy (dans Microsoft.SharePoint.Taxonomy.dll)

Syntaxe

'Déclaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class ContentTypePublisher
'Utilisation
Dim instance As ContentTypePublisher
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class ContentTypePublisher

Remarques

Une fois une application de service de métadonnées gérées et son proxy sont mis en service et un site a été désigné comme le concentrateur sur l'application de service, utilisez cette classe pour publier ou annuler la publication des types de contenu sur le site du concentrateur.

En outre, utilisez cette classe pour vérifier si un type de contenu sur ce site de concentrateur est publié et pour vérifier si la fonction MetadataHub est activée sur le concentrateur.

Exemples

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");
            }

        }
    }
}

Cohérence de thread

Tous les membres statique (Partagé dans Visual Basic)s publics de ce type sont thread-safe. Cela n’est pas garanti pour les membres d’instance.

Voir aussi

Référence

ContentTypePublisher - Membres

Microsoft.SharePoint.Taxonomy.ContentTypeSync - Espace de noms