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
)
参数
parentContentType
类型:Microsoft.SharePoint.SPContentType从中派生此内容类型的内容类型。
collection
类型:Microsoft.SharePoint.SPContentTypeCollection此内容类型添加到集合。
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();