SPFieldLink 构造函数
初始化具有指定字段的SPFieldLink类的新实例。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Sub New ( _
field As SPField _
)
用法
Dim field As SPField
Dim instance As New SPFieldLink(field)
public SPFieldLink(
SPField field
)
参数
field
类型:Microsoft.SharePoint.SPField要引用的列。请注意此对象必须表示现有网站或列表列。即,它必须包含在由SPWeb.Fields属性或SPList.Fields属性返回的SPFieldCollection对象中。
备注
创建一个SPFieldLink对象后,它的一些属性都初始化为SPField对象作为参数传递给构造函数的相应属性的值。下表中列出了属性和它们的值。
属性 |
从值 |
---|---|
示例
下面的示例显示的控制台应用程序将SPField对象添加到网站的SPFieldCollection,然后使用对象来创建一个SPFieldLink对象,并将该对象添加到内容类型的SPFieldLinkCollection的一部分。
请注意您可以使用新的字段创建SPFieldLink对象之前,域必须级别的网站或列表字段集合的成员。
Dim site As SPSite = New SPSite("https://localhost")
Dim web As SPWeb = site.OpenWeb()
' Get the site content type collection.
Dim contentTypes As SPContentTypeCollection = web.ContentTypes
' Create a Customer content type derived from the Contact content type.
Dim contentType As SPContentType = New SPContentType(contentTypes("Contact"), contentTypes, "Customer")
' Add the content type to the site collection.
contentTypes.Add(contentType)
' Get the site fields (columns) collection.
Dim siteFields As SPFieldCollection = web.Fields
' Create a new field (column) and add it to the site collection.
Dim fieldName As String = siteFields.Add("Last Order", _
SPFieldType.DateTime, False)
' Create a reference to the new field.
Dim fieldLink As SPFieldLink = _
New SPFieldLink(siteFields.GetField(fieldName))
' Add the field reference to the content type.
contentType.FieldLinks.Add(fieldLink)
' Commit changes to the content type.
contentType.Update()
' Clean up.
web.Dispose()
site.Dispose()
SPSite site = new SPSite("https://localhost");
SPWeb web = site.OpenWeb();
// Get the site content type collection.
SPContentTypeCollection contentTypes = web.ContentTypes;
// Create a Customer content type derived from the Contact content type.
SPContentType contentType = new SPContentType(contentTypes["Contact"],
contentTypes, "Customer");
// Add the content type to the site collection.
contentTypes.Add(contentType);
// Get the site fields (columns) collection.
SPFieldCollection siteFields = web.Fields;
// Create a new field (column) and add it to the site collection.
string fieldName = siteFields.Add("Last Order", SPFieldType.DateTime, false);
// Create a reference to the new field.
SPFieldLink fieldLink = new SPFieldLink(siteFields.GetField(fieldName));
// Add the field reference to the content type.
contentType.FieldLinks.Add(fieldLink);
// Commit changes to the content type.
contentType.Update();
// Clean up.
web.Dispose();
site.Dispose();