Share via


How to: Reference a Column in a Content Type

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

You can specify column references in a content type definition, so that each time a user provisions a content type of that type, the content type references the columns by default. Content type definitions can be included in Features. For more information, see Working with Features.

After a user adds a content type to a site, you can reference columns in that content type by using the Windows SharePoint Services object model.

Specifying Column References in a Content Type Definition

If you want to reference a column in a content type definition that is part of a Feature, you must add the necessary XML element to the content type definition. Then, when a user provisions a content type of that type, the column is referenced in the content type by default.

To reference a column to a content type definition

  1. In the content type definition XML, add a FieldRef Element (ContentType) element to the FieldRefs Element (ContentType) element.

  2. To define the field as you want, set the attributes of the FieldRef Element (ContentType) element.

If you make changes to a column reference on a content type that has been provisioned, Windows SharePoint Services never writes those changes back to the XML column definition itself. Instead, Windows SharePoint Services stores updates made to column references as entries within the Windows SharePoint Services database. For more information, see Updating Site Columns.

Referencing Columns in a Provisioned Content Type

You can use the Windows SharePoint Services object model to programmatically reference columns in provisioned content types.

To reference a column in a provisioned content type

  1. Use the FieldLinks property to access the collection of column references in the specified content type. This method returns an SPFieldLinkCollection object.

  2. Use the Add method to add a column reference to the content type.

    Columns are included in content types by reference, rather than directly. For more information, see Fields and Field References.

    Note

    The Fields property returns an SPFieldCollection object. Each SPField in this collection represents a "merged view" of the base column definition and any overwritten properties specified in the column reference in the content type. Because of this, you cannot add columns directly to this collection. Attempting to do so results in an error.

See Also

Tasks

How to: Add a Column to a List

How to: Add a Column to a Site

Concepts

Introduction to Columns

Adding Columns in Content Types to Lists