共用方式為


ContentTypeCollection 類別

表示網站或清單內容類型的集合。

繼承階層架構

System.Object
  Microsoft.SharePoint.Client.ClientObject
    Microsoft.SharePoint.Client.ClientObjectCollection
      Microsoft.SharePoint.Client.ClientObjectCollection<ContentType>
        Microsoft.SharePoint.Client.ContentTypeCollection

命名空間:  Microsoft.SharePoint.Client
組件:   Microsoft.SharePoint.Client.Silverlight (在 Microsoft.SharePoint.Client.Silverlight.dll 中);  Microsoft.SharePoint.Client.Phone (在 Microsoft.SharePoint.Client.Phone.dll 中)  Microsoft.SharePoint.Client (在 Microsoft.SharePoint.Client.dll 中)

語法

'宣告
Public NotInheritable Class ContentTypeCollection _
    Inherits ClientObjectCollection(Of ContentType)
'用途
Dim instance As ContentTypeCollection
public sealed class ContentTypeCollection : ClientObjectCollection<ContentType>

備註

Document library templates sample app for SharePoint示範如何使用此物件。

範例

此程式碼範例初始化自訂內容類型,將它加入各種內容類型,並顯示指定的網站的內容類型的名稱。

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointFoundation.Samples
{
    class ContentTypeCollectionExample
    {
        static void Main()
        {

            string siteUrl = "http://MyServer/sites/MySiteCollection";

            ClientContext clientContext = new ClientContext(siteUrl);
            Web site = clientContext.Web;
            ContentTypeCollection collContentType = site.ContentTypes;

            // Initialize a new content type.
            ContentTypeCreationInformation contentInfo = new ContentTypeCreationInformation();
            contentInfo.Name = "myContentType";
            contentInfo.Description = "My custom content type";
            ContentType contentType = collContentType.Add(contentInfo);

            clientContext.Load(collContentType);
            clientContext.ExecuteQuery();

            foreach (ContentType myType in collContentType)
                Console.WriteLine("Content Type Name: {0}", myType.Name);
        }

    }
}

執行緒安全

這類型的任何公用 static (共用 於 Visual Basic 中) 成員是安全執行緒。不保證任何執行個體成員都是安全執行緒。

請參閱

參照

ContentTypeCollection 成員

Microsoft.SharePoint.Client 命名空間