SPFieldLink class
Represents a single column (also known as field) reference that is included in a content type.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
If you want to track certain item metadata in a content type, you can reference a column that represents that metadata. However, you cannot create a column in a content type; you must create the column separately and then reference it in the content type definition. As a result, when you add a column to a content type, the content type contains a reference to the column (or field), rather than the column (or field) itself.
The reference contains a subset of the properties of the full field definition. These are the properties you can customize for the column as it exists in the content type.
For more information, see Fields and Field References.
The SPContentType object contains both a SPFieldLinkCollection and an SPFieldCollection object.
The SPFieldCollection object provides you with a combined view of a column's attributes, as they exist in the specified content type. Each SPField object represents all the attributes of a column or field definition, combined with those attributes that have been overridden in the field reference for that content type.
When you access an SPField object in a content type, SharePoint Foundation combines the field definition with the field reference and returns the resulting SPField object. This is helpful because you do not have to look up a field definition and all the attributes in the field definition that are overridden by the field reference for that content type.
There is a 1-to-1 correlation between the items in the SPFieldLinkCollection and SPFieldCollection objects. For each SPFieldLink object that you add to a content type, SharePoint Foundation adds a corresponding SPField object that represents the combined view of that column as defined in the content type.
Note |
|---|
SharePoint Foundation does not support inheriting from the SPFieldLink class. |
The following example shows a console application that creates a content type, applies it to a list, and adds references to fields at both the site and list level.
The application prints the following output to the console.
Site content type FieldLink.DisplayName = Product FieldLink.DisplayName = Owner List content type FieldLink.DisplayName = Product FieldLink.DisplayName = Owner FieldLink.DisplayName = SKU Press ENTER to continue...
Note