コンテンツ タイプ シンジケートのカスタマイズ

最終更新日: 2010年4月21日

適用対象: SharePoint Server 2010

コンテンツ タイプ シンジケートによって、リストの均一性が確保され、すべてのリストで同じコンテンツ タイプ、つまり、同じ列が使用されます。Microsoft Office SharePoint Server 2007 では、コンテンツ タイプはサイトコレクション レベルで設定されます。Microsoft SharePoint Server 2010 でコンテンツ タイプ シンジケートを使用すると、ファーム内、または Managed Metadata Service アプリケーションを備えるファーム外部で共有できます。

オブジェクト モデルを使用して、コンテンツ タイプ シンジケートをカスタマイズし、新しいコンテンツ タイプの作成、発行、および発行取り消しができます。以下のコード例では、ContentTypePublisher クラスが紹介されています。Managed Metadata Service アプリケーションとそのプロキシを準備し、サイトをサービス アプリケーションのハブとして指定した後で、このクラスを使用してハブ サイトでコンテンツ タイプの発行または発行取り消しを行います。また、このクラスを使用して、このハブ サイトでコンテンツ タイプが発行されているかどうか、およびメタデータ ハブ機能がハブで有効になっているかどうかを確認します。

多くの場合、ハブは発行者として機能し、Web アプリケーションまたはサイト コレクションは、ハブが発行するコンテンツを購読します。コンテンツ タイプが発行されると、サブスクライバーは、タイマー ジョブを使用してコンテンツ タイプを取得します。ユーザーは、[サーバーの全体管理] ページに移動し、Web アプリケーションをハブとして選択できます。個々の Web アプリケーションも、選択したハブを共有アプリケーション データ (コンテンツ タイプなど) のプロバイダーとして購読できます。

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
    {
        /// Demostrates how to use the ContentTypePublisher class by creating a 
        /// content type and then publishing it and unpublishing it.
        /// Before this method is called, a Managed Metadata service application
        /// should be created and a hub should be designated on the service application.
        /// <param name="hubSite">
        /// The site that is 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 the 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 to see whether 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 to see whether 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 whether 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");
            }

        }
    }
}

関連項目

概念

メタデータおよび分類プログラミング モデル

メタデータを管理する

管理されたメタデータ フィールド値に対してクエリを実行する