MOSS8 / Create Site Columns in SharePoint Server

SharePoint team and Project server team at Maven Infosoft has great experience of creating web application based on MOSS 2007 and Project server 2007. That includes customization and development of webpart, site definitions, theme development, extension development, module creation. The team has developed CRM application, Job portal, Project management, to CMS applications based on MOSS 2007 and project server 2007.

Team would like to share same experience. This can help who wanted to begin with the sharePoint development and Project Server development.

There are list of articles start with SP and from number 1 to …. Always start with the article SP1 and read next article to start working on MOSS easily and quickly.

Creating Site Columns:

In this 3 part series I will explain the steps you need to follow in order to create site columns, content types and page layouts for use with a MOSS publishing site.

There is already quite some information to be found on the internet on how to create site columns and custom lists using a feature, however most part apply to team sites (WSS3 sites), not MOSS publishing sites.

Field definition schema:

Site columns are created by placing <Field> elements inside an <Elements> tag. It is important to review the <Field> element definition before going any further. The complete schema definition is detailed in the WSS3 SDK which can be consulted online on the MSDN site (http://msdn2.microsoft.com/en-us/library/ms437580.aspx). On the mentioned URL you can find all the types of fields available out of the box, the required attributes, possible values and so forth.

This is very good documentation for WSS3 fields but information on extra field types for publishing site columns is not available. At least I was unable to find it in the MOSS SDK or online. My solution was to look at the feature definitions used by MOSS publishing feature available out of the box.

Most of the attributes of the <Field> element are optional. This is a sample field definition using the most common attributes:

<Field

ID=”{4C67267C-B950-4cd4-8038-DEACA9EC2F74}”
Name=”IntroductionText”
StaticName=” IntroductionText ” SourceID=”http://schemas.microsoft.com/sharepoint/v3″
Group=”My publishing fields group”
DisplayName=”Introduction text field”
Type=”Text”
Required=”FALSE”
Sealed=”TRUE”
MaxLength=”250″>

</Field>

When using other types of fields there are extra attributes that are useful.

A note about the sealed attribute: setting this to “TRUE” will ensure the field cannot be removed via the “Change column” page. However when you are creating a choice field (a dropdown, a checkbox list), and you want your users to be able to edit the list of values you need to set sealed to FALSE.

Some attributes are only used in combination with some types of fields, like for example the StorageTZ attribute, which is useful together with Type=”DateTime”.

When it comes to publishing field types there are some new types that you can use. As far as I could find they are not yet documented. By looking at the “PublishingResources” hidden feature I could find the following:

Field type Description Related attributes
Image Publishing field for storing an image. The edit control shows the Insert picture button. RichText=”TRUE”
RichTextMode=”FullHtml”
HTML HTML editing control RichText=”TRUE” RichTextMode=”FullHtml”
Link Hyperlink control

In edit mode, allows the user to select an internal file (also external links can be allowed)

In display mode shows the clickable link to the file

RichText=”TRUE” RichTextMode=”FullHtml”
SummaryLinks Field control for editing a list of links

There are also some extra fields that are related to the page publishing content types such as “Publishing schedule start date”. I don’t think you’d like to use these as the page content types normally already inherit these types of columns.

As a sample for this and the following posts in this series I’m creating a product page content type. My product contains 8 fields going from name and description, date, image, price.

This is the XML schema (myfields.xml):

<?xml version=”1.0″ encoding=”utf-8″ ?>
<!– _lcid=”1033″ _version=”12.0.4017″ _dal=”1″ –>
<!– _LocalBinding –>
<!–
–>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<Field ID=”{F44BFBB0-4725-4167-B976-F85F84131AA3}” Name=”ProductCategory” StaticName=”ProductCategory” SourceID=”http://schemas.microsoft.com/sharepoint/v3″ Group=”$Resources:column_group_products;” DisplayName=”$Resources:column_productcategory_displayname;” Type=”Choice” Format=”Dropdown” Required=”FALSE” Sealed=”FALSE”>
<CHOICES>
<CHOICE>$Resources:column_productcategory_choice1;</CHOICE>
<CHOICE>$Resources:column_productcategory_choice2;</CHOICE>
<CHOICE>$Resources:column_productcategory_choice3;</CHOICE>
</CHOICES>
</Field>
<Field ID=”{EB19D87C-5DEE-4a73-85E0-506293D422D9}” Name=”ProductName” StaticName=”ProductName” SourceID=”http://schemas.microsoft.com/sharepoint/v3″ Group=”$Resources:column_group_products;” DisplayName=”$Resources:column_productname_displayname;” Type=”Text” Required=”TRUE” Sealed=”TRUE” MaxLength=”255″></Field>
<Field ID=”{D73843E5-0D9F-4400-BC75-1A4C2BD27900}” Name=”ProductIntro” StaticName=”ProductIntro” SourceID=”http://schemas.microsoft.com/sharepoint/v3″ Group=”$Resources:column_group_products;” DisplayName=”$Resources:column_intro_displayname;” Type=”Text” Description=”$Resources:column_intro_description;” Required=”TRUE” Sealed=”TRUE” MaxLength=”500″ NumLines=”2″></Field>
<Field ID=”{894635F9-1DF8-46f1-BC47-46EFF09FEF3D}” Name=”ProductDescription” StaticName=”ProductDescription” SourceID=”http://schemas.microsoft.com/sharepoint/v3″ Group=”$Resources:column_group_products;” DisplayName=”$Resources:column_productdesc_displayname;” Type=”HTML” Required=”FALSE” Sealed=”TRUE” RichText=”TRUE” RichTextMode=”FullHtml”></Field>
<Field ID=”{D89C9409-2A97-4a7a-81F5-7D45E7CD8D6B}” Name=”LaunchDate” StaticName=”LaunchDate” SourceID=”http://schemas.microsoft.com/sharepoint/v3″ Group=”$Resources:column_group_products;” DisplayName=”$Resources:column_date_displayname;” Type=”DateTime” Format=”DateTime” Required=”TRUE” Sealed=”TRUE” StorageTZ=”UTC”></Field>
<Field ID=”{6036ECDE-521A-4dbe-94B4-40E0E4EF7029}” Name=”ProductImage” StaticName=”ProductImage” SourceID=”http://schemas.microsoft.com/sharepoint/v3″ Group=”$Resources:column_group_products;” DisplayName=”$Resources:column_image_displayname;” Type=”Image” Required=”FALSE” Sealed=”TRUE” RichText=”TRUE” RichTextMode=”FullHtml”></Field>
<Field ID=”{6A08E31A-0620-45df-BAC1-54A4D0FBFDCE}” Name=”ProductManual” StaticName=”ProductManual” SourceID=”http://schemas.microsoft.com/sharepoint/v3″ Group=”$Resources:column_group_products;” DisplayName=”$Resources:column_manual_displayname;” Type=”Link” Required=”FALSE” Sealed=”TRUE” RichText=”TRUE” RichTextMode=”FullHtml”></Field>
<Field ID=”{F31DF817-D220-4449-BD6F-2F1B7C0823ED}” Name=”ProductPrice” StaticName=”ProductPrice” SourceID=”http://schemas.microsoft.com/sharepoint/v3″ Group=”$Resources:column_group_products;” DisplayName=”$Resources:column_productprice_displayname;” Type=”Currency” Required=”TRUE” Sealed=”TRUE” Decimals=”2″></Field>
</Elements>

To install the field definitions via a feature I’m creating a feature.xml file that refers to the myfields.xml. In the feature file I also add a dependency to the PublishingSite feature.

A note about resources files:

As you may notice in the display name and description attributes I’m referring to a resource instead of typing in the text. I recommend using resource files whenever translatable (non system name) text is used.

Living in Belgium, a country where we have three official languages I’m used to creating multi-lingual applications. Even when a first requirement does not specify a multi-lingual approach I still prefer to foresee resource files.

When creating features you can use local resource files by placing them in a sub-folder in the feature directory.