Share via


How to: Add a Column to a Site

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 columns in a site definition so that each time a user provisions a site of that type, Windows SharePoint Services includes the column as an available site column. Site definitions can also be included in Features. For more information, see Working with Features.

After a user has provisioned a site, you can add site columns to that site through the Windows SharePoint Services object model.

Specifying a Site Column in a Site Definition

To add a site column to a site definition that is part of a Feature, you must add the necessary XML element to the site definition. Then, when a user provisions a site of that type, the column is included by default in the site column collection.

To specify a site column in a site definition in a Feature

  1. Create the field as a separate Feature.

    For more information, see Working with Features and Field Definition Schema.

  2. Reference that Feature in the Feature that defines your site:

    1. In your site Feature, open the XML file that defines your site.

    2. In the Project element, under the Categories and Category elements, add a reference to the content type Feature in either the SiteFeatures or WebFeatures element. Following is an example.

      [xml]
      <SiteFeatures>
        <Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />
        <Feature ID="695B6570-ACDC-4A8E-8545-26EA7FC1D162" />
      </SiteFeatures>
      <WebFeatures>
        <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />
        <Feature ID="00BFEA71-E717-4E80-DEAF-D0C71B360101" />
      </WebFeatures>
      

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

Adding a Column to a Provisioned Site

You can use the Windows SharePoint Services object model to programmatically add columns to provisioned sites.

To add a column to a provisioned site

  1. To access the collection of site columns on the specified site, use the Fields property. This property returns an SPFieldCollection object.

  2. To add a new column to the site, use one of the following methods of the returned SPFieldCollection object:

See Also

Tasks

How to: Add a Column to a List

How to: Reference a Column in a Content Type

Concepts

Introduction to Columns

Adding Columns in Content Types to Lists