Like This ...

How to Use CAML

CAML allows you the ultimate flexibility and extensibility with your Web sites based on SharePoint Team Services from Microsoft. If you want to make a universal change to all the sites that you are creating within your company — for instance, you want to change the logo to match your own company logo, or you want to add an Employee ID field to your document libraries — you must use CAML to do it.

Since CAML is located within several of the folders installed with SharePoint Team Services, you might want to review the Location of CAML topic as you read through these examples.

Each example is designed to show you creative ways to implement changes by using CAML. As you walk through them, you will gain a better understanding of how CAML is used throughout your sites.

The following examples have been provided for you:

 

Example 1 - Adding a new field type for Flash movies

To add a new field type for Flash movies, do the following:

  1. Go to Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\xml and open FLDTYPES.XML.
  2. Add a new Row element to FLDTYPES.XML by copying an existing Row section from another field type (for example, the one that defines the Text type).
  3. Change the TypeName field to be appropriate for displaying Flash animations by modifying the first Field element in the section, such as follows:

<Field Name="TypeName" DisplayName="TypeName">Flash</Field>

  1. Change the DisplayPattern field to be appropriate for displaying Flash animations by modifying the contents of the RenderPattern section used to define the display pattern. Add a Flash object to the definition as follows:
  2. <RenderPattern Name="DisplayPattern" DisplayName="DisplayPattern">
  3.   <HTML><![CDATA[ <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  4.     codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH=600 HEIGHT=450>
  5.     <PARAM NAME=movie VALUE="]]>
  6.   </HTML>
  7.   <Column HTMLEncode="TRUE" AutoNewLine="TRUE"/>
  8.   <HTML><![CDATA["> <PARAM NAME=quality VALUE=high>
  9.     <PARAM NAME=bgcolor VALUE=#FFFFFF> <EMBED src="]]>
  10.   </HTML>
  11.   <Column HTMLEncode="TRUE" AutoNewLine="TRUE"/>
  12.   <HTML><![CDATA[" quality=high bgcolor=#FFFFFF WIDTH=600 HEIGHT=450 TYPE="application/x-shockwave-flash"
  13.     PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>
  14.     </OBJECT>]]>
  15.   </HTML>

</RenderPattern>

  1. Create a new template by copying the CustList folder and naming the new folder appropriately (for this example, Movies).
  2. Update the new directory's SCHEMA.XML file to have a field that uses the new Flash animation type. In the empty Fields element after the opening <MetaData> tag, add an appropriate Field element as follows:

<Field Type="Flash" Name="FlashMv" DisplayName="URL" Required="TRUE"></Field>

  1. Add the new template to ONET.XML so that the new type shows up on the SharePoint Team Services Create page. In the ListTemplates section, add a template definition like the following:
  2. <ListTemplate Name="Movies" DisplayName="Movies" Type="132" BaseType="0" Default="FALSE" OnQuickLaunch="FALSE"

  SecurityBits="111" Description="Create a new Flash movies list." Image="_layouts/images/ittask.gif"></ListTemplate>

Note   The value of the Type attribute must be a number that is not being used elsewhere in the ListTemplates section and that is less than 1000. The Name attribute must be set to the exact name of the new custom list folder.

  1. On the SharePoint team Web site's Create page, create a new list based on the template, adding the appropriate URL for the Flash movie on the New Item form.

 

Example 2 — Customizing the logo on your team Web sites

To customize the logo used on new SharePoint team Web sites, do the following:

  1. Open the Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\Images directory.
  2. Copy the image you want to appear on the home page of your team Web site to this directory.
  3. Delete the SharePoint Team Services logo HOME.GIF.
  4. Rename the new image HOME.GIF.
  5. Create a new subweb.

All sites created from now on will have the new image as a logo.

 

Example 3 - Customizing the top link bar

To add a new item to the top link bar of your SharePoint team Web site, do the following:

  1. In the Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\xml directory, open ONET.XML.
  2. At the top of the ONET.XML file, find the TopMenuItems section. The first item listed in the collection corresponds to the item that appears farthest to the left on the link bar.
  3. Add a new node where you would like the new item to appear on the link bar, including the file name of the page you want to link to, such as follows:

<TopMenuItem Name="NewNavigationItem" DisplayName="New Navigation Item" Url="_layouts/NewNavigationItem.htm"/>

Note   The URL is relative to the root of the SharePoint team Web site.

  1. Add your new page to the Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\Layouts directory.
  2. Create a new subweb.

All new sites will contain your new page in their individual _layouts folder within the wwwroot directory, and the top link bar will now include a link to the new page.

 

Example 4 - Adding a new document type and file type icon

To add a document type and type icon, do the following:

  1. In the Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\xml directory, open DOCICON.XML.
  2. In the middle of the file, find the ByExtension section.
  3. For the sake of example, we will add a wav file type and an icon to represent what kind of file it is. Add a line like the following:

<Mapping Key="wav" Value="icwav.gif"/> 

  1. In the Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\Images directory, add an appropriate icon and call it "icwav.gif".
  2. Restart Microsoft Internet Information Services (IIS).
  3. Create a new subweb.

All sites created from now on will display icwav.gif in document libraries for files that have the .wav extension.

 

Example 5 - Adding a field to a list in a custom document library

To add a field to a list for a document library, do the following:

  1. Open the Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\Layouts directory.
  2. Copy the entire contents of the DocLib folder to the directory, renaming the copy, for example, MyDocLib.
  3. In the new MyDocLib directory, open SCHEMA.XML.
  4. Find the Fields element within the opening MetaData section. Between the opening and closing <Fields> tags, add a Field element like the following:
  5. <Field Name="EmployeeID" DisplayName="Employee ID" Type="Number" Required="TRUE"

  Description="Enter the ID from your employee badge."/>

  1. In the Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\xml directory, open the file named ONET.XML.
  2. Find the ListTemplates section, and before the closing <ListTemplates> tag add a new ListTemplate element that looks like the following sample:
  3. <ListTemplate Name="MyDocLib" Default="FALSE" Type="501" BaseType="1"
  4.   DisplayName="Document Library with Employee ID" SecurityBits="111"

  Description="This document library has an additional employee ID field." Image="_layouts/images/itdl.gif"/>

This entry in ONET.XML describes how your custom document library will appear on the SharePoint Team Services Create page (http://Server/Subweb/_layouts/create.htm).

The value of the Type attribute must be a number that is not being used elsewhere in the ListTemplates section and that is less than 1000 (the 501 above is just an example). The Name attribute must be set to the exact name of the new document library folder.

You can replace itdl.gif with your own image by adding your image to Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\Images.

Note that if you set the Default attribute to TRUE in the ListTemplate element above, all subsequently created team Web sites will have this document library. If you do this, you should also change the Title and Name attributes of the List element and the body of the DefaultDescription element in MyDocLib\SCHEMA.XML.

From now on users will have this new document library available to them when they create lists.

 

Example 6 - Adding a title link to an item in a document list

To add a title link in a document list, do the following:

  1. In the Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\xml directory, open ONET.XML.
  2. Find the BaseTypes section and, within this section, find the BaseType element where the Type attribute is set to 1.
  3. In the Fields section within the MetaData element for this base type, add the following entry:

<Field ReadOnly="TRUE" Type="Computed" Name="LinkedToTitle"

  DisplayName="Document Title" DisplayNameSrcField="Title"

  AuthoringInfo="(linked to document)">

  <FieldRefs>

    <FieldRef Name="Title"/>

    <FieldRef Name="FileRef"/>

  </FieldRefs>

  <DisplayPattern>

    <HTML><![CDATA[<A HREF="]]></HTML>

    <HttpHost URLEncodeAsURL="TRUE"/>

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

    <HTML><![CDATA[">]]></HTML>

    <Switch>

      <Expr>

        <Column Name="Title"/>

      </Expr>

      <Case Value="">

        <UrlBaseName HTMLEncode="TRUE">

          <LookupColumn Name="FileRef"/>

        </UrlBaseName>

      </Case>

      <Default>

        <Column Name="Title" HTMLEncode="TRUE"/>

      </Default>

    </Switch>

    <HTML><![CDATA[</A>]]></HTML>

  </DisplayPattern>

</Field>

  1. Save ONET.XML.
  2. Create a new document library.

The document library has an extra field, Document Title (linked to document), that may be added to views of that document library. It is a computed field that consists of a link to the document. The text of this link is the title of the document (if it has any title at all); otherwise, it is the file name. This is accomplished via the Switch statement.

 

Example 7 - Adding an in-line, highly customized view

To add an in-line, highly customized view for a list:

  1. Using Microsoft FrontPage, create a new page in a Web site based on SharePoint Team Services from Microsoft.
  2. In HTML View, add the following <META> tag in the document's HEAD section:

<META Name="Microsoft SharePoint Content Type" Content="Dynamic">

  1. Within the document's BODY section, add the following CAML source:

<ows:XML>

  <SetList>Announcements</SetList>

  <View>

    <ViewFields>

      <FieldRef Name="LinkTitle" Explicit="TRUE"/>

      <FieldRef Name="Expires"/>

      <FieldRef Name="Body"/>

    </ViewFields>

    <ViewBody>

      <HTML><![CDATA[<h1>]]></HTML>

      <Field Name="LinkTitle"/>

      <HTML><![CDATA[</h1><ol>]]></HTML>

      <Fields>

        <HTML><![CDATA[<li>]]></HTML>

        <Field/>

        <HTML><![CDATA[</li>]]></HTML>

      </Fields>

      <HTML><![CDATA[</ol><hr>]]></HTML>

    </ViewBody>

  </View>

</ows:XML>

  1. Save and view the page.

As a result, a new view of the announcements list is created. The LinkTitle field is specially handled in that it is displayed via an <H1> tag. All the other view fields are handled as list items inside an ordered list. A horizontal rule separates one list record from the next.

Note   This example assumes that the built-in Announcements list has not been deleted.

 

Example 8 — Creating a new template for custom lists

To create a new template for custom lists, do the following:

  1. Go to the Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\Layouts directory and copy the CustList folder, renaming the new folder appropriately.
  2. In this new directory, open the file SCHEMA.XML.
  3. Add as many field definitions as needed to SCHEMA.XML in the empty Fields element just after the opening <MetaData> tag. The following example defines fields for a sign-up sheet that has drop-down lists:

<Fields>

  <Field Name="LinkTitle" DisplayName="Driver" Required="TRUE"/>

  <Field Name="Title" DisplayName="Driver" Required="TRUE"/>

  <Field Name="ParkingLocation" Type="Choice" DisplayName="Park & Ride Location" Required="TRUE">

    <CHOICES>

      <CHOICE>Eastgate Mall</CHOICE>

      <CHOICE>North Park</CHOICE>

      <CHOICE>South Terrace Center</CHOICE>

      <CHOICE>Lake Shores Park & Ride</CHOICE>

    </CHOICES>

  </Field>

  <Field Name="ToWork" Type="Choice" DisplayName="To Work" Required="TRUE">

    <CHOICES>

      <CHOICE>7am</CHOICE>

      <CHOICE>8am</CHOICE>

      <CHOICE>9am</CHOICE>

      <CHOICE>10am</CHOICE>

    </CHOICES>

  </Field>

  <Field Name="FromWork" Type="Choice" DisplayName="From Work" Required="TRUE">

    <CHOICES>

      <CHOICE>4pm</CHOICE>

      <CHOICE>5pm</CHOICE>

      <CHOICE>6pm</CHOICE>

      <CHOICE>7pm</CHOICE>

    </CHOICES>

  </Field>

  <Field Name="Capacity" Type="Number" DisplayName="Capacity" Required="TRUE"/>

  <Field Name="Preferences" Type="Note" DisplayName="Personal Preferences"/>

</Fields>

  1. Search for the ViewFields element within the AllItems section of SCHEMA.XML and add field references, as follows:

<ViewFields>

  <FieldRef Name="LinkTitle"></FieldRef>

  <FieldRef Name="ParkingLocation"></FieldRef>

  <FieldRef Name="ToWork"></FieldRef>

  <FieldRef Name="FromWork"></FieldRef>

  <FieldRef Name="Capacity"></FieldRef>

  <FieldRef Name="Preferences"></FieldRef>

</ViewFields>

  1. Go to the Program Files\Common Files\Microsoft Shared\web server extensions\50\Templates\1033\xml directory and open ONET.XML.
  2. To make the new list template available on the Create page for the SharePoint team Web site, add a definition for a list template to the ListTemplates section, as follows:

<ListTemplate Name="Commuting" DisplayName="Shared Rides" Type="133" BaseType="0" Default="FALSE" OnQuickLaunch="FALSE" SecurityBits="111"

    Description="Save gas and enjoy the ride to work with co-workers." Image="_layouts/images/ittask.gif"></ListTemplate>

Note   The value of the Type attribute must be a number that is not being used elsewhere in the ListTemplates section and that is less than 1000. The Name attribute must be set to the exact name of the new custom list folder.

  1. The new template now appears on the Create page and custom lists can be added to the team Web site.

 

Example 9 - Using ScreenTips to show list data

To add ScreenTips to the display of an Events list, do the following:

Note   Custom ScreenTips are supported in Microsoft Internet Explorer version 4.0 and later.

  1. Using Microsoft FrontPage, create a new page on a Web site that is based on SharePoint Team Services from Microsoft.
  2. In HTML view, add the following STYLE information in the document's HEAD section:

<META Name="Microsoft SharePoint Content Type" Content="Dynamic">

  1. Within the document's BODY section, add the following CAML source:

<ows:xml>

  <SetList>Events</SetList>

  <View Name='AnyName' FreeForm='TRUE'>

    <ViewFields>

    <FieldRef Name="LinkTitle"/>

    <FieldRef Name="Location"/>

    </ViewFields>

  <ViewBody>

     <HTML><![CDATA[<TABLE><TR><TD>]]></HTML>

     <HTML><![CDATA[<SPAN TITLE="Location:&nbsp;]]></HTML>

     <Field Name='Location'/>

     <HTML><![CDATA[">]]></HTML>

     <Field Name='LinkTitle'/>

     <HTML><![CDATA[</SPAN>]]></HTML>

     <HTML><![CDATA[</TD></TR></TABLE>]]></HTML>

  </ViewBody>

  </View>

</ows:xml>

  1. Save and view the page.

As a result, a new view of the Events list is created. The LinkTitle field is specially handled in that, when you place the pointer over the LinkTitle text, a ScreenTip is created to display the contents of the Location field.

Note   This example assumes that the built-in Events list has not been deleted.

 

blog comments powered by Disqus