ContentTypePublisher-Klasse

Veröffentlicht oder unpublishes ein Inhaltstyps für die Hubwebsite.

Vererbungshierarchie

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

Namespace:  Microsoft.SharePoint.Taxonomy.ContentTypeSync
Assembly:  Microsoft.SharePoint.Taxonomy (in Microsoft.SharePoint.Taxonomy.dll)

Syntax

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

Hinweise

Nach einer Dienstanwendung für verwaltete Metadaten und Stellvertreter bereitgestellt werden und eine Website als Hub für die Dienstanwendung benannt wurde, verwenden Sie diese Klasse zum Veröffentlichen oder Aufheben der Veröffentlichung der Inhaltstypen für die Hubwebsite.

Verwenden Sie diese Klasse auch überprüfen, ob ein Inhaltstyp auf Hub-Standort veröffentlicht wird und zu überprüfen, ob die MetadataHub-Funktion auf dem Hub aktiviert ist.

Beispiele

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

        }
    }
}

Threadsicherheit

Alle öffentlichen static (Shared in Visual Basic) Member dieses Typs sind threadsicher. Die Threadsicherheit von Instanzmembern ist nicht gewährleistet.

Siehe auch

Referenz

ContentTypePublisher-Member

Microsoft.SharePoint.Taxonomy.ContentTypeSync-Namespace