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
)

参数

备注

创建一个SPFieldLink对象后,它的一些属性都初始化为SPField对象作为参数传递给构造函数的相应属性的值。下表中列出了属性和它们的值。

属性

从值

Hidden

SPField.Hidden

Id

SPField.Id

Name

SPField.InternalName

Required

SPField.Required

示例

下面的示例显示的控制台应用程序将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();

另请参阅

引用

SPFieldLink 类

SPFieldLink 成员

Microsoft.SharePoint 命名空间

其他资源

Fields and Field References

FieldRef Element (ContentType)

Introduction to Columns

Introduction to Content Types