SPContentType 构造函数 (SPContentType, SPContentTypeCollection, String)

初始化使用指定的父内容类型的SPContentType类的新实例。

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
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
    类型:System.String

    内容类型的名称。此字符串被设置为新的内容类型中的Name属性的值。

异常

异常 条件
SPException

不能修改集合。

ArgumentException

SPListparentContentType驻留在其为 null 。

AD 访问控制

已从其父SPContentTypeCollectionparentContentType 。

备注

作为第二个参数传递给构造函数的集合对象用于获取属性的新内容类型的某些初始值。但是,新的内容类型是不自动添加到集合中。您必须执行该自己在后续调用Add(SPContentType)方法。

此构造函数将新对象的Name属性的值设置为name参数中传递的值。

示例

下面的示例创建一个派生自"Item"类型,然后将新类型添加到网站集的内容类型。

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 类

SPContentType 成员

SPContentType 重载

Microsoft.SharePoint 命名空间

其他资源

Introduction to Content Types

Site and List Content Types

Base Content Type Hierarchy