Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
General Reference
Columns
 How to: Reference a Column in a Con...
Community Content
In this section
Statistics Annotations (0)
This page is specific to
The 2007 product release

Other versions are also available for the following:
How to: Reference a Column in a Content Type

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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker