You are not Logged in
Would you like to Login or Register

Today is: 04 July 2009
Check this months hot topics

WSS 3.0 : Add a Column(Field) to a List (Part 1)

In order to add a Column (Computed) to a List you will need to use the WSS Object Model. As there are no tools to do this currently (however I am currently writing a little tool to help.) you will need to understand the CAML to define a Field.

In this case I wanted to add a field that contained a link to a Client Dashboard, so the following XML will do this.

<Field Name="LLClientDashboard" Group="_Hidden" Type="Computed" Sortable="FALSE" Filterable="FALSE" DisplayName="Client Dashboard" AuthoringInfo="(linked to item)" StaticName="LLClientDashboard" >
    <FieldRefs>
         <FieldRef ID="{94f89715-e097-4e8b-ba79-ea02aa8b7adb}" Name="FileRef" />
                <FieldRef Name="ID" />
     </FieldRefs>
     <DisplayPattern>
         <HTML><![CDATA[<a href="]]></HTML>
             <HttpHost />
             <UrlDirName>
                 <HTML>/</HTML>
                     <LookupColumn URLEncodeAsURL="TRUE" Name="FileRef" />
             </UrlDirName>
             <HTML><![CDATA[/lists/clients/clientdashboard.aspx?ID=]]></HTML>
             <Column HTMLEncode="TRUE" Name="ID" />
             <HTML><![CDATA[" onclick="GoToLink(this);return false;" target="_self">]]></HTML>
             <HTML>Client Dashboard</HTML>
             <HTML><![CDATA[</a>]]></HTML>
      </DisplayPattern>
</Field>

A description of each of the fields can be found http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spfield_members.aspx . However, the Display pattern needs further understanding.

All HTML must be wrapped in a HTML and CDATA Element.

<HTML><![CDATA[<a href="]]></HTML>

This will render out the HTTP Host being used by the Site (HTTP or HTTPS)

<HttpHost />

This will use the Fireref Field which is on all lists to render out the URL of the current folder that this list is in.

<UrlDirName>
    <HTML>/</HTML>
    <LookupColumn URLEncodeAsURL="TRUE" Name="FileRef" />
</UrlDirName>

The rest is simply what we want displayed in the link, however please note the javascript to actually navigate to the page. This is not strictly required, but it will pass the source address to the linked page therefore allowing Sharepoint to send you back here if you press the Cancel Button

<HTML><![CDATA[/lists/clients/clientdashboard.aspx?ID=]]></HTML>
<Column HTMLEncode="TRUE" Name="ID" />
<HTML><![CDATA[" onclick="GoToLink(this);return false;" target="_self">]]></HTML>
<HTML>Client Dashboard</HTML>
<HTML><![CDATA[</a>]]></HTML>

In the Next Part I will show you how to actually use this XML to add a Column to your list, and what other display pattern fields are available to help you render you information in your lists.

kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Greg Duffield Skype
Author : Greg Duffield
Published : 23 July 2007

Greg has too many years experience in developement from VB for DOS all the way through to Windows Workflow and LINQ while covering pretty much every technology in between. A complete MS evangelist he is now Director of the only MS Gold Partner IT services company in Norfolk. Wehere they are producing Web 2 Applications for various sectors, and are currently entering the Haulage industry with their latest product.

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views