SPFieldLink constructor

Initializes a new instance of the SPFieldLink class with the specified field.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPFieldLink(
	SPField field


Type: Microsoft.SharePoint.SPField

A column to reference. Note that this object must represent an existing site or list column. That is, it must be contained in the SPFieldCollection object that is returned by the SPWeb.Fields property or the SPList.Fields property.

When an SPFieldLink object is created, some of its properties are initialized to the values of corresponding properties of the SPField object that is passed as an argument to the constructor. The properties and their values are listed in the following table.

The following example shows part of a console application that adds an SPField object to the site’s SPFieldCollection, then uses the object to create an SPFieldLink object, and adds that object to a content type’s SPFieldLinkCollection.

Note that before you can use a new field to create an SPFieldLink object, the field must be a member of a field collection at either the site or list level.

SPSite site = new SPSite("http://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.

// 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.

// Commit changes to the content type.

// Clean up.