共用方式為


SPContentType constructor (SPContentType, SPContentTypeCollection, String)

初始化使用指定的父系內容類型的SPContentType類別的新執行個體。

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

Syntax

'宣告
Public Sub New ( _
    parentContentType As SPContentType, _
    collection As SPContentTypeCollection, _
    name As String _
)
'用途
Dim parentContentType As SPContentType
Dim collection As SPContentTypeCollection
Dim name As String

Dim instance As New SPContentType(parentContentType, _
    collection, name)
public SPContentType(
    SPContentType parentContentType,
    SPContentTypeCollection collection,
    string name
)

參數

  • name
    Type: System.String

    內容的型別名稱。這個字串已設定為新的內容類型中的Name屬性的值。

Exceptions

Exception Condition
SPException

無法修改集合。

ArgumentException

SPListparentContentType所在是 null 。

-或-

已從其父代SPContentTypeCollection移除parentContentType 。

備註

將做為第二個引數傳遞至建構函式的集合物件用來取得特定屬性的新內容類型的起始值。不過,新的內容類型是並不會自動加入至集合。您必須執行該自己的Add(SPContentType)方法的後續呼叫中。

這個建構函式會將新物件的Name屬性的值設定為傳入的name引數的值。

Examples

下列範例會建立內容的型別衍生自 [項目] 類型,然後將新的型別加入至網站集合。

Dim site As SPSite = New SPSite("https://localhost")
Dim web As SPWeb = site.OpenWeb()

' Get a reference to the site content type collection.
Dim contentTypes As SPContentTypeCollection = web.ContentTypes

' Create a Customer content type derived from the Item content type.
Dim contentType As SPContentType = New SPContentType(contentTypes("Item"), contentTypes, "Customer")

' Add the content type to the site collection.
contentType = contentTypes.Add(contentType)

' Clean up.
web.Dispose()
site.Dispose()
SPSite site = new SPSite("https://localhost");
SPWeb web = site.OpenWeb();

// Get a reference to the site content type collection.
SPContentTypeCollection contentTypes = web.ContentTypes;

// Create a Customer content type derived from the Item content type.
SPContentType contentType = new SPContentType(contentTypes["Item"], contentTypes, "Customer");

// Add the content type to the site collection.
contentType = contentTypes.Add(contentType);

// Clean up.
web.Dispose();
site.Dispose();

請參閱

參照

SPContentType class

SPContentType members

SPContentType overload

Microsoft.SharePoint namespace

其他資源

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy