Part I – Creating site columns, publishing content types and page layout using a feature

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.
Screenshot here.

In the next post I will explain how to add a content type definition and use the fields created in this post.

Just a final note for the first post: the installation batch file I use to install a feature can be found here.


 

 


 

Feedback

Posted on 05 June 2007 @ 13:56

Hi Katrien,

Just wondering if you found a problem with using the 'Link' field type in a page layout. I created one using a feature, along with the other publishing field types, and used them to create a page layout. Once I created a page from the layout and went into edit mode, none of the link fields appear for edit (the other publishing field types work fine). I specified them exactly as per your blog - they're not set to be hidden or anything.

I also noticed that when creating them through the UI I sometimes got cast errors (none of my own code, it was MOSS) with the link type, so I'm wondering if someone else might have experienced either of these things, and whether you actually were able to use the link fields while editing a WCM page.

Thanks,
Gillian

Posted on 06 June 2007 @ 09:38

Hi Gillian,
I did not yet have any problems with the Link field type.
Are you also inserting the related properties (RichText="TRUE" RichTextMode="FullHtml")?
If you wish you can send me a sample of what you are doing.

I've already used the Link field a number of times without any problems.

Posted on 24 June 2007 @ 21:37

Hi Katrien, thanks for your reply - I've since deployed my Link fields to a different dev environment and found that they work just fine. Something's seriously wrong with my original dev environment - I still can't see them in edit mode - but then I've noticed other funny behaviour on it that I've not experienced before. Such is life with MOSS I guess!

Gillian

Posted on 06 July 2007 @ 12:31

Hi Katrien

Thanks for three very interesting articles. You have indeed very good knowledge about this subject. Keep up the good work!

/Göran
MOSS MVP

Posted on 07 July 2007 @ 14:37

Thanks Göran, there is still a lot to be learned about MOSS for me but I'm on the way.

Katrien

Posted on 17 August 2007 @ 15:28

FYI, the attachments refer to the "admin" version; the URLs should point to the shared version, e. g. http://www.katriendg.com/aboutdotnet/attachments/
200703/screenshot_resources.JPG
.

Posted on 19 August 2007 @ 14:21

Mike,
Thanks for pointing that out. I've corrected the links in the post.

Posted on 05 May 2008 @ 10:48

please give links to your next posts in this article.

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Copyright © 2007 Katrien De Graeve.