SPContentType.FieldLinks 属性
获取SPFieldLinkCollection值,该值代表的内容类型中的列或字段,引用的集合。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public ReadOnly Property FieldLinks As SPFieldLinkCollection
Get
用法
Dim instance As SPContentType
Dim value As SPFieldLinkCollection
value = instance.FieldLinks
public SPFieldLinkCollection FieldLinks { get; }
属性值
类型:Microsoft.SharePoint.SPFieldLinkCollection
在内容类型的字段引用的集合。
备注
如果您想要跟踪的内容类型中某些项元数据,可以引用代表该元数据的列。但是,您无法在内容类型 ; 创建列您必须创建列,然后在内容类型定义中引用该。因此,列添加到内容类型后,内容类型不包含列或字段 ;它包含引用中的列中,或字段中,。
有关详细信息,请参阅Fields and Field References。
SPContentType对象包含SPFieldLinkCollection和SPFieldCollection对象。
因为它们存在于该内容类型, SPFieldCollection对象为开发人员提供一种方法来获取列的属性的组合的视图。每个SPField对象代表一个列或字段中,定义,与该内容类型字段引用中已重写这些属性组合的所有属性。
在访问内容类型中SPField时, SharePoint Foundation合并字段引用中,使用的字段定义,并生成SPField对象返回给您。这样可以防止开发人员不必查找字段定义,然后查找所替代,该内容类型的字段引用的字段定义中的所有属性。
因此,没有SPFieldLinkCollection和SPFieldCollection对象中的项之间的 1-1 关联。对于您将添加到内容类型每个SPFieldLink , SharePoint Foundation添加一个代表该列的合并的视图,规定的内容类型中的相应SPField对象。
您无法直接添加或删除SPContentType对象 ; 中SPFieldCollection对象中的项目如果您尝试执行此操作,将引发错误。
示例
下面的示例是一个控制台应用程序创建新的字段,并将其添加到网站的SPFieldCollection的一部分。然后应用程序创建新的SPFieldLink对新列的引用,并将其添加到内容类型的**[SPFieldLinkCollection]**集合。最后,该应用程序更新的内容类型,将更改提交到数据库。
字段必须存在之前的网站的字段集合中的注释可用于创建SPFieldLink对象。
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 Contact content type.
Dim contentType As SPContentType = New SPContentType(contentTypes("Contact"), contentTypes, "Customer")
' Put the content type in a group.
contentType.Group = "Test"
' Add the content type to the site collection.
contentTypes.Add(contentType)
' Get a reference to 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 a reference to 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 a reference to 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();