RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Exploit SharePoint List Definitions to Maximize Your Brand : Page 4

You can customize site definitions and add functionality to list editing tools, but if your branding and tools strategies aren't implemented in your list definitions, then your site isn't completely following those strategies. Find out how list definitions work, what their relationship is to site definitions, and how to change the appearance and the structure of the list.

Changing the Structure of the List
One of the beautiful things about a list definition is that you can define a rich set of predefined lists that already contains the fields and views that you need to solve a problem. Most of the list formats that SharePoint offers, with the notable exception of the issues list, are little more than a custom list defined with a set of predefined fields that make sense for a specific purpose. The contacts list is, as the name suggests, good for maintaining a list of contacts. The links list is good for capturing links, the tasks list is good for capturing tasks, and so on.

For this article's purposes, you're going to further modify the contacts list to add a new field. This new field will be designed to capture the type of the contact in the contact list. For instance, the contact can be: an acquaintance, a friend, a colleague, a competitor, a vendor, a customer, or some other kind of contact. Before you can add this field to the list definition, you have to create the CAML fragment that represents the field.

Because this is a choice field, the values are a bit more complicated. The basic format for a field is a single <Field> node. A choice field has the additional sub-nodes of <Default> and <CHOICES>. The <CHOICES> node further has one or more <CHOICE> nodes indicating the individual choices for the field.

The three basic attributes required for a <Field> node are:

  • Name: This is the InternalName used in SharePoint. It must be unique. The name is only seen by developers working on code that works with the list.
  • Display Name: This is the name that users see for the field. It is displayed in data entry screens and as the header for views of the list.
  • Type: This is the fundamental type of the field. For instance, Text, Note, URL, and Choice are all different fundamental types of fields.
When using a choice field, in addition to these attributes, you'll also need the Format attribute to indicate the form of choice (DropDown), and the FillInChoice attribute which indicates whether the user can type in a response. Putting this all together, the CAML fragment for the field is:

<Field Type="Choice" DisplayName="TypeOfContact" Format="Dropdown" FillInChoice="FALSE" Name="TypeOfContact">
With the CAML fragment in hand, you can add the field to the list definition. The following steps show you how to add a field to a list definition:
  1. Open the SCHEMA.XML.
  2. Locate the List\MetaData\Fields node.
  3. Before the closing tag of the <Fields> node, add the new <Field> node for the field that you want to add.
  4. Save the file.
  5. Perform an IISRESET.
  6. Create a new list from the list definition and verify that the field is present.
A Flexible Framework for Customization
SharePoint provides a extremely flexible framework for customizing the way that your lists look and work. You can change the structure of the list pages much like you can change the structure of the main Web part pages in a site definition. You can also control the Web parts on the page just as you can in a site definition. Further, you can control the types of fields that are created when the list is created. This means that you can develop nearly every kind of list that you can dream up.

Robert Bogue, MCSE (NT4/W2K), MCSA:Security, A+, Network+, Server+, I-Net+, IT Project+, E-Biz+, CDIA+ has contributed to more than 100 book projects and numerous other publishing projects. He was recently honored to become a Microsoft MVP for Microsoft Commerce Server and before that Microsoft Windows Servers-Networking. Robert blogs at http://www.thorprojects.com/blog.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date