SCHEMA.XML


The relationship between SCHEMA.XML and the ASPX/HTM files in the list definition is akin to ASPX's code-behind concept. SCHEMA.XML should be thought of as the code-behind, whereas ASPX and HTM files represent the presentation code. In fact, the web part zone in the ASPX page and a web part zone-like component in the HTM file are the receptacles for SCHEMA.XML's CAML execution.

As mentioned previously, ONET.XML overlaps SCHEMA.XML's functionality in some places. In these cases, ONET.XML's settings will override SCHEMA.XML, or vice versa. You therefore need to be aware of these nuances when modifying list definitions and should check both files if the list does not appear as you feel it should.

The structure of SCHEMA.XML is shown in Listing 3.1. The major elements are List, Fields, Views, Forms, DefaultDescription, and Toolbar.

Listing 3.1. SCHEMA.XML Structure

 <List>   <MetaData>     <Fields />     <Views />     <Forms />     <DefaultDescription />     <Toolbar />   </MetaData> </List> 

<List>: Top-Level List Definition Settings

List provides some top-level settings. Many of the List attributes were covered in Table 2.9 during our discussions of ONET.XML. In this section, we will expand on our discussion of the List element. Listing 3.2 shows the default List element for a document library in the STS site definition. As previously mentioned, if these same attributes are specified in ONET.XML, they can take precedence over those specified within SCHEMA.XML.

Listing 3.2. SCHEMA.XML Document Library List Element Declaration

 <List xmlns:ows="Microsoft SharePoint" Name="Documents"       Title="Shared Documents" Direction="0" Url="Shared Documents"       BaseType="1"> 

If our site definition includes the code from Listing 3.2 and Listing 3.3, the values of Title and Url specified in ONET.XML will be used over those specified in SCHEMA.XML.

Listing 3.3. ONET.XML Configuration for Team Site

 <Configurations>       <Configuration  Name="NewWeb"/>       <Configuration  Name="Default">             <Lists>             <List Title="Documents"               Url="Documents"               QuickLaunchUrl="Documents/Forms/AllItems.aspx"               Type="101" /> . . . 

The BaseType attribute specified in the List element refers to a particular base type defined within ONET.XML. Recall that the base types specify a base schema (columns) for the list types. This base schema can be developed once and then applied to the various list types as appropriate. For example, the BaseType of 1 is applied document libraries, picture libraries, and form libraries.

Configuring Event Handlers

Some of the more powerful list customizations for document, picture, and form libraries are event sinks. With event sinks, your custom code can hook into SharePoint library eventscheck in, check out, and so on. Event sinks only apply to libraries and do not apply to other types of lists.

It should be noted that these events are fired after the operation is performed. For example, the delete event is fired after a document is deleted from a document library. The next version of SharePoint will feature events that fire before the operation is performed. However, if you cannot wait until the next version of SharePoint, you might want to consider writing your own HTTP Module to act on requests immediately before SharePoint acts on them.

Assuming you have enabled event handlers for your Virtual Server (see Figure 3.7), SharePoint can pass the document library events to a specified EventSinkAssembly and EventSinkClass. Additionally, you can specify EventSinkData that will be passed with the event information to the specified assembly and class. This capability is useful if you have one generic assembly responding to events from various sources. Your event handler can therefore react appropriately to the event depending on what the associated EventSinkData is passed to the handler. Because you can attach only one assembly to each document library in this version of SharePoint, creating a generic assembly to respond to events from different libraries is a good practice to follow.

Figure 3.7. Virtual Server General Settings with Event Handlers enabled.


Figure 3.8 shows the advanced settings of a document library. The Advanced Settings page is where you can manually specify a custom event handler through the web user interface. Alternatively, you could use the List element's EventSinkAssembly, EventSinkClass, and EventSinkData attributes within the site definition's ONET.XML to avoid this manual task.

Configuring event handlers in a library can be incredibly useful. One scenario underscoring their usefulness would be processing newly uploaded documents in a document library. For instance, a newly uploaded Excel file could be processed to extract data to update an enterprise application.

The page in Figure 3.8 is also where a Microsoft Exchange public folder can be specified. If specified, SharePoint will download its content into the SharePoint document library. Site definitions provide no way to bind a library with an Exchange public folder. However, this does not preclude writing code that interacts with the SharePoint API to configure this setting. This code could be embedded within NEW.ASPX and run immediately after a document library was created.

Figure 3.8. Document Library Advanced Settings.


<Fields>: Defining Additional Columns over the Base Type

The Fields element can define list columns and can define how a list is rendered. In the former case, we use the Fields element to add additional fields to what was defined by the base list type. In the latter case, the Fields element is embedded within the Views and Forms elements along with quite a bit of other CAML.

In Listing 3.4, we examine defining the Title and Expiration Date fields in our document library through the Fields element. Title is a holdover from the SCHEMA.XML taken from the STS site definition. Expiration Date is something we will be adding to our MyFirstSiteDefinition site definition. It represents a date at which the document content is considered stale and therefore out of date.

Listing 3.4. SCHEMA.XML Adding Fields to a Document Library

 <Fields>   <Field Type="Text" Name="Title" ShowInNewForm="FALSE"          ShowInFileDlg="FALSE" DisplayName="Title" Sealed="TRUE"/>   <Field Type="DateTime" Name="ExpirationDate" ShowInNewForm="TRUE"          ShowInFileDlg="TRUE" DisplayName="Expiration Date"          Required="TRUE" Sealed="TRUE">     <DefaultFormula>       =DATE(YEAR(Today)+3,MONTH(Today),DAY(Today))     </DefaultFormula>   </Field> </Fields> 

Because we do not want the ExpirationDate element to be removed, we have set the Sealed attribute to TRUE. The effects are shown in Figure 3.9. As you can see from the figure, sealing the field restricts more than the option to delete the column. The data type, data type formatting, default value, and whether it is required are also inaccessible to the user.

Figure 3.9. FLDEDIT.ASPX Expiration Date as a sealed column.


We have also set the ShowInNewForm, ShowInFileDlg, and Required attributes to trUE. ShowInNewForm specifies whether the field should show up in UPLOAD.ASPX. As shown in Figure 3.10, ShowInNewForm for Expiration Date was set to true, whereas for Title, it was set to false. In contrast, ShowInFileDlg specifies whether the field should show up in EDITDLG.HTM (refer to Figure 3.5), which is accessible from Microsoft Office applications. The Required attribute forces a user to select a non-blank value for that column. The caveat is that this constraint is not enforced when a file is uploaded through the Explorer View. In that case, there is no facility to specify a value, and it will be set to null.

Figure 3.10. UPLOAD.ASPX Expiration Date as a required column.


A default value of three years from today was set for the ExpirationDate column. This was done through the DefaultFormula element. We used the functions defined within the Formulas and Functions section of SharePoint's online helpwhich is shown in Figure 3.11. It is interesting to note that these functions are not explicitly defined within the SharePoint CHM help file.

Figure 3.11. SharePoint Help on Functions.


Although we have touched on a number of Field attributes, we have merely scratched the surface of its capabilities. The complete list of Field's attributes are summarized in Table 3.2.

Table 3.2. <Field> Attributes

Attribute

Required

Type

Description

Aggregation

No

Text

This is used as an aggregate field in an XML form. The possible aggregations include sum, count, average, min, max, merge, text, first, and last.

AllowHyperlink

No

Boolean

If trUE, hyperlinks can be used.

AllowMultiVote

No

Boolean

If TRUE, multiple responses to a survey are permitted.

AuthoringInfo

No

Text

A hidden description that is primarily used as a way to explain the differences between two columns that have the same display name.

BaseType

Yes

Text

This can be set to either Integer or Text. Text is the default.

CanToggleHidden

No

Boolean

If TRUE, the column can be hidden through the user interface.

ClassInfo

No

Text

Specifies the CSS class to be applied to this column.

ColName

No

Text

Specifies the content database column in the database table that maps to the field. This is primarily used with base types in ONET.XML.

Commas

No

Boolean

If trUE, commas are used for thousands separators.

Decimals

No

Integer

The number of decimal places to store. For instance, specifying 2 for this attribute will store 1.051 as 1.06.

Description

No

Text

Specifies the description of the field. This will be viewable by users.

Dir

No

Text

This specifies the direction of the text in the field. 0 is left to right, and 1 is right to left. This is very similar to the Direction attribute in the List element.

DisplayImage

No

Text

Specifies the URL to an icon to be displayed in the column.

DisplayName

No

Text

Specifies a friendly name for the field that will be exposed to users. The value of the Name attribute is not exposed to users.

DisplayNameSrcField

No

Text

Links the field to another. This is primarily used in cases where there are two fields with the same display name and if the first field's display name changes, you want this field's display name to appear to match that change.

Div

No

Number

Specifies a scale factor by which to divide the value of the field.The value of the column is calculated as Field Value Mult / Div.

FieldRef

No

Text

Specifies another field that can be used as a lookup for this field.

FillInChoice

No

Boolean

If TRUE, the user can specify a value for the field.

Filterable

No

Boolean

If trUE, the field can be filtered on.

ForcedDisplay

No

Text

Specifies static text to be used in place of a field's value.

Format

No

Text

Specifies the numeric formatting. For Date fields, valid values include DateOnly, DateTime, ISO8601, and ISO8601Basic. For Choice fields, valid values include Dropdown and RadioButtons. For URL fields, valid values include Hyperlink (uses A tag) or Image (uses IMG tag).

FromBaseType

No

Boolean

Deprecated. Use Sealed.

HeaderImage

No

Text

Specifies an image that will appear in the field's header.

Hidden

No

Boolean

If trUE, the field is hidden. The column will not be accessible through the SharePoint web user interface. However, it can still be displayed in views if those views were defined through the site definition template.

HTMLEncode

No

Boolean

If trUE, the value of the field is HTML encoded so that it does not conflict with HTML elements on the page.

JoinColName

No

Text

Like the ColName attribute, this references a database column. This specifies a column to join on in local and foreign lists.

JoinType

No

Text

Specifies the type of SQL join to use with JoinColName. Values include INNER, LEFT OUTER, and RIGHT OUTER.

LCID

No

Integer

Specifies the locale identifier for the field if it is different from the LCID of the Share-Point installation.

List

No

Text

Specifies the database table name to join with.

Max

No

Number

Specifies a maximum value for the field.

MaxLength

No

Integer

Specifies a maximum number of characters for the field.

Min

No

Number

Specifies a minimum value for the field.

Mult

No

Number

Specifies a scale factor by which to multiply the underlying value of the field. The value of the column is calculated as Field Value Mult / Div.

Name

No

Text

Specifies the internal name of the field.

NegativeFormat

No

Text

Specifies how to indicate negative values. Allowed values include MinusSign and Parens.

Node

No

Text

Used in XML forms to specify the XPath expression.

NoEditFormBreak

No

Boolean

If TRUE, line breaks are prevented from being added to the field. This will apply to the view properties and edit properties forms.

NumLines

No

Integer

Specifies a hint/recommendation for the number of lines to display for a TextArea HTML element.

Percentage

No

Boolean

If trUE, the value will be displayed as a percentage. Thus, 0.01 will be displayed as 1%.

PIAttribute

No

Text

Used in XML forms to provide attribute details for XML processing instructions.

PITarget

No

Text

Used in XML forms to provide a link to the form's template.

Presence

No

Boolean

If trUE, the field user presence information is included in the field.

PrimaryKey

No

Boolean

If trUE, the field is the primary key for the list. This is important for providing a relationship to another list.

ReadOnly

No

Boolean

If TRUE, the field is not editable. It therefore will not be displayed in new and edit forms.

RenderXMLUsingPattern

No

Boolean

This affects the display format of calculated fields. If trUE, the field is rendered based on its display pattern type instead of the field's true type.

Required

No

Boolean

If TRUE, the web user interface will require that a non-null value be specified. As discussed previously, this can be subverted. For instance, the document library's explorer view will allow null values for extended metadata.

RichText

No

Boolean

If trUE, the field can contain rich text.

Sealed

No

Boolean

If TRUE, the field cannot be changed or deleted.

SeparateLine

No

Boolean

Internal attribute (do not use). If trUE, rendering is continued on a separate line.

ShowAddressBookButton

No

Boolean

Internal attribute.

ShowField

No

Text

Specifies the field to display when joining to an external list (database table).

ShowInEditForm

No

Boolean

If trUE, the field will be displayed in the Edit Item page.

ShowInFileDlg

No

Boolean

If TRUE, the field will be displayed in the file dialog that is accessed through Microsoft Office applications.

ShowInNewForm

No

Boolean

If TRUE, the field will be displayed in the New or Upload Item page.

Sortable

No

Boolean

If trUE, the list can be sorted on this field.

StorageTZ

No

Text

Specifies how the date/time will be serialized to the database.

StripWS

No

Boolean

If TRUE, leading and trailing white spaces are removed from the value.

SuppressNameDisplay

No

Boolean

If trUE, the user name will not be displayed in the User field.

TextOnly

No

Boolean

If TRUE, the field will contain only string or text values.

Type

No

Text

Specifies the data type of the field. Valid values include Attachments, Boolean, Choice, Computed, Counter, CrossProjectLink, Currency, DateTime, File, Guid, Integer, Lookup, ModStat, MultiChoice, Note, Number, Recurrence, Text, Threading, URL, and User.

URLEncode

No

Boolean

If TRUE, the values in the field are URL Encoded. This is similar to HTMLEncode.

URLEncodeAsUrl

No

Boolean

If trUE, the value in the field is URL Encoded; however, the forward slashes are not encoded.

Viewable

No

Boolean

If TRUE, the field should be added to the default view.

Xname

No

Text

Internal attribute. Identifies XML form attributes that have been added, deleted, or modified.


<Fields>: Advanced Concepts

In the previous section, we concentrated our efforts on a simple exampleadding a document expiration field to a document library. In this section, we explain the Fields element's link to the database.

Ultimately the individual list fields are stored in the database. The primary table where list items are stored is UserData, which is found in every content database. Additional list items can be retrieved from other database tables through database joins. Listing 3.5 showcases some of these joins to other tables.

Listing 3.5. ONET.XML Document Library Base Type Definition

 <BaseType Title="Document Library" Image="_layouts/images/itdl.gif"           Type="1">   <MetaData>     <Fields>       <Field ColName="tp_ID" ReadOnly="TRUE" Type="Counter" Name="ID"              DisplayName="ID"/>       <Field ColName="tp_Created" Hidden="TRUE" ReadOnly="TRUE"              Type="DateTime" Name="Created" DisplayName="Created Date"              StorageTZ="TRUE"/>       <Field ColName="tp_Author" ReadOnly="TRUE" Type="User"              List="UserInfo" Name="Author" DisplayName="Created By"/>       <Field ColName="tp_Modified" Hidden="TRUE" ReadOnly="TRUE"              Type="DateTime" Name="Modified" DisplayName="Last Modified"              StorageTZ="TRUE"/>       <Field ColName="tp_Editor" ReadOnly="TRUE" Type="User"              List="UserInfo" Name="Editor" DisplayName="Modified By"/>       <Field ColName="tp_ModerationStatus" ReadOnly="TRUE"              Type="ModStat" Name="_ModerationStatus"              DisplayName="Approval Status" Hidden="TRUE"              CanToggleHidden="TRUE" Required="FALSE">         <CHOICES>           <CHOICE>0;#Approved</CHOICE>           <CHOICE>1;#Rejected</CHOICE>           <CHOICE>2;#Pending</CHOICE>        </CHOICES>        <Default>0</Default>       </Field>       <Field ReadOnly="TRUE" Type="Note" Name="_ModerationComments"              DisplayName="Approver Comments" Hidden="TRUE"              CanToggleHidden="TRUE" Sortable="FALSE"/>       <Field Name="FileRef" ReadOnly="TRUE" Hidden="TRUE"              Type="Lookup"              DisplayName="URL Path" List="Docs" FieldRef="ID"              ShowField="FullUrl" JoinColName="DoclibRowId"              JoinType="INNER"/>       <Field Name="FileDirRef" ReadOnly="TRUE" Hidden="TRUE"              Type="Lookup" DisplayName="URL Dir Name" List="Docs"              FieldRef="ID" ShowField="DirName"              JoinColName="DoclibRowId"              JoinType="INNER"/>       <Field Name="Last_x0020_Modified" ReadOnly="TRUE"              DisplayName="Modified" Type="Lookup" List="Docs"              FieldRef="ID" ShowField="TimeLastModified"              Format="TRUE"              JoinColName="DoclibRowId" JoinType="INNER"/>       <Field Name="Created_x0020_Date" ReadOnly="TRUE"              DisplayName="Created" Type="Lookup" List="Docs"              FieldRef="ID" ShowField="TimeCreated" Format="TRUE"              JoinColName="DoclibRowId" JoinType="INNER"/>       <Field Name="File_x0020_Size" Hidden="TRUE" ReadOnly="TRUE"              Type="Lookup" DisplayName="File Size" List="Docs"              FieldRef="ID" ShowField="SizeInKB" Format="TRUE"              JoinColName="DoclibRowId" JoinType="INNER"/> . . . 

The entire document library base type is defined within ONET.XML. Listing 3.5 defines only the top portion of this definition. This base type retrieves information from the UserData, UserInfo, and Docs database tables.

The first bold field definition in Listing 3.5 defines the approval status. The ColName attribute specifies that the column will be stored in the tp_ModerationStatus database column. The lack of a List attribute implies that its value will reside in the UserData database table. Furthermore, the three choicesApproved, Rejected, and Pendingwill be serialized as 0, 1, and 2, respectively. tp_ModerationStatus has a data type of int, so saving these values as anything other than an integer is not acceptable. If a column name is not specified, SharePoint will choose one for you.

The second bold field definition in Listing 3.5 defines the file size (File_x0020_Size). This definition is a bit more complicated. The field's value is defined in the Docs table and not UserData, Furthermore, the size data retrieved from the Docs table is further computed (see Listing 3.6) to return the size in kilobytes.

The file size field references the Docs table through the List attribute. The field also defines an inner join where Docs.DoclibRowId equals UserData.tp_ID. Docs.Size is selected from the resulting join and returned as the field's value. It was the computation that we alluded to previously that helped map ID to tp_ID and SizeInKB to Size (see Listing 3.6).

This translation needs to happen because the FieldRef and Show-Field attributes reference other field definitions. Let's first search for the ID field defined by FieldRef. This ID field is the first field element defined earlier in Listing 3.5. As specified in its definition, it maps to the tp_ID database field in UserData. The definition for SizeInKB can be found in BASE.XML located in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\XML folder (assuming your LCID is 1033).

The kilobyte size field definition is bolded in Listing 3.6. This translation specifies a database column of Size and a scaling division factor of 1024. Thus, DOCS.Size will be retrieved and divided by 1024. Furthermore, the user will see this value with a friendly column name of File Size.

Listing 3.6. BASE.XML Docs Database Table Mapping

 <List Name="Docs" Title="Documents">   <MetaData>     <Fields>       <Field ReadOnly="TRUE" Type="Guid" Name="ID" ColName="Id"              Sortable="FALSE" DisplayName="ID"></Field>       <Field Type="Text" Name="FullUrl" ColName="FullUrl"              TextOnly="TRUE" Sortable="FALSE"              DisplayName="Name"></Field>       <Field Type="Text" Name="DirName" ColName="DirName"              TextOnly="TRUE" Sortable="FALSE"              DisplayName="Name"></Field>       <Field Type="Text" Name="LeafName" ColName="LeafName"              TextOnly="TRUE" Sortable="TRUE"              DisplayName="Name"></Field>       <Field Type="Guid" Name="DoclibRowId" ColName="DoclibRowId"              Sortable="FALSE" DisplayName="Doclib Item ID"></Field>       <Field Type="Integer" Name="Size" ColName="Size"              ReadOnly="TRUE"              Hidden="TRUE" Sortable="TRUE"              DisplayName="File Size"></Field>       <Field Type="Integer" Name="SizeInKB" Div="1024"              ColName="Size"              ReadOnly="TRUE" Hidden="TRUE" Sortable="TRUE"              DisplayName="Size (KB)"></Field> . . 

<Views>: Defining List Views

The Views element defines the initial views for the list. You are no doubt familiar with the All Documents and Explorer views of a document library. These, along with three other views, are defined within SCHEMA.XML for the standard document library.

You might recall that in Table 2.12, we enumerated the attributes of the View element. The View element is the only child element allowed for Views. In Listing 3.7, we show the top-level nodes of all the views within a document library. Unfortunately, the View definitions are quite large and therefore difficult to dissect in detail. For example, the view definition for ALLITEMS.ASPX spans approximately 1,500 lines.

Listing 3.7. SCHEMA.XML Document Library Views Structure

 <Views>   <View BaseView Type="HTML">   .   .   .   <View BaseView Type="HTML" WebPartZone         DisplayName="All         Documents" DefaultView="TRUE" Url="Forms/AllItems.aspx">   .   .   .   <View BaseView Type="HTML" FileDialog="TRUE"         DisplayName="File         Dialog View" Hidden="TRUE" Path="filedlg.htm"         ModerationType="Moderator">   .   .   .   <View BaseView Type="HTML" WebPartZone         DisplayName="Explorer View" Url="Forms/WebFldr.aspx"         ReadOnly="TRUE">   .   .   .   <View BaseView Type="HTML">   .   .   . </Views> 

By looking at the Path and Url attributes, you have probably surmised that the View with a BaseViewID of 1 maps to the All Document view, the one with a BaseViewID of 2 maps to the dialog rendered from Microsoft Office, as shown previously in Figure 3.4, and finally the BaseViewID of 3 maps to the Explorer view.

You've probably also noticed the references to web part zones in these three views. They are rendered within a web part zone on the Url or Path specified page. This means that anything outside of this web part zone is not modifiable through SCHEMA.XML. In these cases, the ASPX or HTM page must be modified.

Creating an Additional View

Our emphasis in this section will be adding an additional view based on the All Documents view. This view will be entitled Expired Documents.

So now you are probably rolling your eyes and saying, "These views are 1,500+ lines long, and you want me to create one?" Well, it actually is much simpler than it sounds. We can recycle almost everything from the All Documents view and tweak the rest. Alternatively, we could design a custom list template and capture the appropriate CAML code from MANIFEST.XML. Of course you could painstakingly look up all the CAML elements instead of generating a custom list template. However, it is generally far easier to recycle code from MANIFEST.XML.

Let's start by designing our custom list template. Because the Expired Documents view requires an ExpirationDate column, we will create one. We need not give it all the properties that our ExpirationDate column in Listing 3.4 defined. The column need only be based on a Date and Time type and could look as simple as Figure 3.12.

Figure 3.12. Expiration Date created within a custom list template.


Next, create a standard view for the Expired Documents and fill it out as shown in Figure 3.13. You will need to specify the view name, the sort order, the group by column, the filter, and enable showing documents without folders.

Figure 3.13. Expired Documents view settings.


As we outlined in Chapter 1, "Custom Templates," save the custom document template to your local drive and examine its MANIFEST.XML file. Search for the View element that defines our newly created Expired Documents view. It should look similar to Listing 3.8.

Listing 3.8. MANIFEST.XML Expired Documents View Partial Listing

 <View Name="{FBB9D2CB-4861-4278-9A03-AF8A8C290C63}" Type="HTML" Scope="Recursive" DisplayName="Expired Documents" Url="Shared Documents/Forms/Expired Documents.aspx" BaseView>   <ViewFields>     <FieldRef Name="DocIcon"/>     <FieldRef Name="LinkFilename"/>     <FieldRef Name="Last_x0020_Modified"/>     <FieldRef Name="Editor"/>     <FieldRef Name="LinkCheckedOutTitle"/>   </ViewFields>   <Query>     <GroupBy Collapse="FALSE">       <FieldRef Name="ExpirationDate"/>     </GroupBy>     <OrderBy>       <FieldRef Name="ExpirationDate"/>     </OrderBy>     <Where>       <Leq>         <FieldRef Name="ExpirationDate"/>         <Value Type="DateTime">           <Today/>         </Value>       </Leq>     </Where>   </Query>   <ViewStyle />   <RowLimit Paged="TRUE">100</RowLimit>   <GroupByHeader> . . . 

From MANIFEST.XML, select the entire View definition (1,500 or so lines) for Expired Documents and then copy it to our SCHEMA.XML. It should be inserted into SCHEMA.XML so that the Views element is its parent. From a best practice standpoint, it should be inserted as the last View definition within Views. However, its placement within the Views element has no effect on its function.

The ViewFields element defines the fields that will be displayed in the view and was generated from the Columns section specified in Figure 3.13. The GroupBy, OrderBy, and Where CAML elements map to the Group By, Sort, and Filter sections of the same figure. Furthermore, the View's Scope attribute corresponds to the Folders section of that same figure.

As mentioned previously, we could have copied the All Documents view definition in SCHEMA.XML and modified the CAML by hand, and we would have achieved the same result. One benefit of harvesting CAML for View definitions, Field definitions, or just about anything else with a list template is that you can usually skip a significant amount of debugging that you might have to perform if done by hand.

The next step is modifying the recently copied View node. You will need to remove the Name attribute, add a WebPartZoneID reference, and modify the Url and BaseViewID. These changes are represented in Listing 3.9.

Listing 3.9. Updated View after Inserting It into SCHEMA.XML

 <View BaseView Type="HTML" WebPartZone       Scope="Recursive" DisplayName="Expired Documents"       Url="Forms/ExpiredDocuments.aspx" > . . . 

The final configuration piece is to make a copy of ALLITEMS.ASPX and name it ExpiredDocuments.ASPX. This additional file is shown in Figure 3.14.

Figure 3.14. ExpiredDocuments.ASPX file added to list definition.


The result of our work is shown in Figure 3.15. We could have added any number of additional views, modified the existing views, or removed some of the views. However, because there are several external references (links) to some of these views, you will need to remove default viewssuch as All Documents and Explorer viewswith care.

Figure 3.15. Expired Documents view.


When we added our view, we selected a BaseViewID of 100 so that it was different from the other BaseViewID values. Every view must have a unique BaseViewID. Furthermore, the BaseViewID defines the view's placement order on the left navigation bar shown in Figure 3.15. The view with the lowest BaseViewID will be placed at the top, whereas the view with the highest BaseViewID will be placed at the bottom of the left navigation bar.

Common <View> Child Elements

Table 3.3 enumerates some of the more popular child elements of View. In the previous section, we designed a view from SharePoint's web user interface and then harvested its CAML code through a list template. The web user interface only controls Aggregations, Query, RowLimit, and ViewStyle. Greater control of views can be achieved with the additional child View elements in Table 3.3.

Table 3.3. Common <View> Child Elements

Element

Description

Aggregations

Specifies how the view should total or calculate columns in the list.

GroupByFooter

Specifies the footer when the query includes a GroupBy and the results are non-null.

GroupByHeader

Defines the header when the query includes a GroupBy and the results are non-null.

PagedRecurrenceRowset

Similar to PagedRowset except that it applies to an event list with recurring events whose total instances exceed the row limit.

PagedRowset

Executes if more items in the view are returned than those specified by the RowLimit element. This will only execute if RowLimit's Paged attribute is set to trUE.

Query

Defines the filter, sort, and/or grouping for the view.

RowLimit

Defines the maximum number of items to show in a view. If Paged is set to TRUE, the view will render the PagedRowset element, and the user will be allowed to continue on to multiple pages. If Paged is set to FALSE, the view will render the RowLimitExceeded element, and the user will not be able to move on to other pages.

RowLimitExceeded

Executes if more items in the view are returned than those specified by the RowLimit element. This will only execute if RowLimit's Paged attribute is set to FALSE.

Toolbar

Defines the toolbar for the view and is rendered above the view header.

ViewBidiHeader

Defines the header for a view column that supports bidirectional reading.

ViewBody

Defines the rendering of rows in a view.

ViewEmpty

Defines the rendering when no items are returned for a view.

ViewFields

Defines the columns/fields to show in the view.

ViewFooter

Defines the footer of columns/fields to render in the view.

ViewHeader

Defines the header of columns/fields to render in the view.

ViewStyle

Applies one of the predefined styles enumerated in the Style section of the Edit View page (refer to Figure 3.13).


The two most commonly used View child elements are Aggregations and Query. Aggregations specifies how the items of a view should be calculated. Query provides a mechanism for filtering, sorting, and grouping a view.

Aggregations

The Aggregations element specifies how items in the view should be calculated. The results of this calculation are typically shown in a header row. An example of Aggregations use is shown in Listing 3.10. In our example, we are counting the number of times the LinkFilename is used.

Listing 3.10. Aggregations Example in SCHEMA.XML

 <Aggregations Value="On">   <FieldRef Name="LinkFilename" Type="COUNT"/> </Aggregations> 

As shown in Figure 3.16, we build on Listing 3.8 with Listing 3.10 to count the number of times LinkFilename is used per grouping along with the total number of times for the list. The practical effect is to count the number of items (rows) in the grouping and the number of items in the list. We could have just as easily specified another column instead of LinkFilename.

Figure 3.16. Expired Documents view with Aggregations specified.


Although only one column is aggregated in the example, you can aggregate any combination of the columns that are present in the view. Furthermore, each column could have a different aggregation type. Those include average, maximum, minimum, summation, standard deviation, and variation. Obviously, these functions lend themselves better to numeric data types than string data types.

Query

The Query element defines the filtering, sorting, and grouping for a view. The valid child elements for Query include GroupBy, OrderBy, and Where. Although GroupBy and OrderBy will never have descendants past children, there is virtually no limit to the number of descendants that Where can have.

Recall that the query for creating our Expired Documents view is shown in Listing 3.8. In that query, we leveraged GroupBy for grouping, OrderBy for sorting, and Where for filtering. As expected, GroupBy and OrderBy only have child elements, but Where has great-grandchildren descendants. The descendants for Where could exist well beyond great-grandchildren when using a logical AND or a logical OR. All the valid child elements of Where are shown in Table 3.4.

Table 3.4. <Where> Child Elements

Element

Description

And

Logical AND.

DateRangesOverlap

Determines whether a recurring event (beginning of event to end of event) overlaps with a specified date. For example, this could be used to show all events that are going on now.

Eq

Equal to.

Geq

Greater than or equal to.

Gt

Greater than.

IsNotNull

Not Empty/Null.

IsNull

Empty/Null.

Leq

Less than or equal to.

Lt

Less than.

Neg

Not equal to.

Or

Logical OR.


Listing 3.11 details an example Where clause that showcases the level of granularity that can be defined with the And and Or elements. The clause is equivalent to (State='Florida' AND City='Miami') AND (Building-Color='Black' OR BuildingColor='Gray').

Listing 3.11. CAML Where Clause Example

 <Where>   <And>     <And>       <Eq>         <FieldRef Name="State"/>         <Value Type="Text">Florida</Value>       </Eq>       <Eq>         <FieldRef Name="City"/>         <Value Type="Text">Miami</Value>       </Eq>     </And>     <Or>       <Eq>         <FieldRef Name="BuildingColor"/>         <Value Type="Text">Black</Value>       </Eq>       <Eq>         <FieldRef Name=" BuildingColor"/>         <Value Type="Text">Gray</Value>       </Eq>     </Or>   </And> </Where> 

<Forms>: Interacting with One Item at a Time

Views are designed to show multiple items from the list. In contrast, forms are designed for just one item. For instance, displaying the properties of an item (DISPFORM.ASPX), editing the properties of an item (EDITFORM.ASPX and EDITDLG.HTM), and the information collected to upload a file to a document library (UPLOAD.ASPX) are all defined within the Forms section of SCHEMA.XML. The basic structure of forms within a document library is shown in Listing 3.12.

Listing 3.12. Basic Forms Structure in a Document Library

 <Forms>   <Form Type="DisplayForm" Url="Forms/DispForm.aspx"         WebPartZone>     <ListFormOpening />     <ListFormButtons />     <ListFormBody />   </Form>   <Form Type="EditForm" Url="Forms/EditForm.aspx" WebPartZone>     <ListFormOpening />     <ListFormButtons />     <ListFormBody />     <ListFormClosing />   <Form Type="NewForm" Url="Forms/Upload.aspx" WebPartZone>     <ListFormOpening />     <ListFormButtons />     <ListFormBody />     <ListFormClosing />   <Form Type="NewFormDialog" Path="EditDlg.htm">     <ListFormOpening />     <ListFormButtons />     <ListFormBody />     <ListFormClosing /> </Forms> 

Table 3.5 details the allowable child elements of Form. To be clear, the content in ListFormOpening, ListFormButtons, ListFormBody and ListFormClosing is not shown in the listing. The form definitions approximate the length of the view definitions and both weigh-in at about 1,500 lines.

Table 3.5. <Form> Child Elements

Element

Description

ListFormOpening

Defines the first section of the form.

ListFormButtons

Defines the toolbars for the form.

ListFormBody

Defines the body of the form.

ListFormClosing

Defines the last section of the form.


<DefaultDescription> Element

The two remaining top-level elements in SCHEMA.XML are Default-Description and Toolbar. DefaultDescription defines a description for the document library, and Toolbar defines a navigation bar. Listing 3.13 details the default description within SCHEMA.XML for a document library.

Listing 3.13. Document Library Description Defined in SCHEMA.XML

 <DefaultDescription>   Share a document with the team by adding it to this document library. </DefaultDescription> 

The effects of this description are shown in Figure 3.17 immediately above the toolbar.

Figure 3.17. Document library using the default description.


Keep in mind that this default description will only be used when the list is created as part of the site definition. When a new list is created in an existing site, the user is prompted for the description (see Figure 3.18). In this scenario, the default description will be blank and will not be pre-populated with the one specified in the site definition.

Figure 3.18. Prompting for description when creating a new document library.


<Toolbar> Element

The Toolbar element defines a block of HTML. Typically this HTML renders a toolbar, but it is not a requirement. In fact, the Toolbar element shown in Listing 3.14 does not render a toolbar. It renders the view's Actions items (Alert me, Export to spreadsheet, Modify settings and columns) on the left bar shown in Figure 3.17.

Listing 3.14. RelatedTasks Toolbar Defined in SCHEMA.XML

 <List xmlns:ows="Microsoft SharePoint" Name="Documents"       Title="Shared Document" Direction="0" Url="Shared Document"       BaseType="1">   <MetaData> . . .     <Toolbar Type="RelatedTasks">       <HTML>         <![CDATA[           <TABLE width=100% cellpadding=0 cellspacing=2                  BORDER=0>             <TR>               <TD width=100% >                 Actions               </TD>             </TR>             <TR>               <TD >                <IMG src="/books/4/78/1/html/2//_layouts/images/blank.gif" width=1 height=1                      alt="">               </TD>             </TR>         ]]></HTML>         <Switch>           <Expr>             <GetVar Name="HasPortal"/>           </Expr>           <Case Value="TRUE"> . . . 

The RelatedTasks toolbar defined in Listing 3.14 is referenced in the ALLITEMS.ASPX page. As shown in Listing 3.15, the SharePoint:RelatedTasks server control renders the toolbar's CAML code. Also shown in the listing is the SharePoint:ViewSelector server control. This renders a list of links to all the appropriate views defined within SCHEMA.XML.

Listing 3.15. Left Navigation from ALLITEMS.ASPX

 <TABLE style="padding-top: 8px" class=ms-navframe CELLPADDING=0        CELLSPACING=0 BORDER=0 width=100%>   <TR>     <TD valign=top width=4px>       <IMG src="/books/4/78/1/html/2//_layouts/images/blank.gif" width=1 height=1 alt="">     </TD>     <TD valign=top ID=onetidSelectView class=ms-viewselect>       <TABLE style="margin-left: 3px" width=115px cellpadding=0              cellspacing=2 BORDER=0>         <TR>           <TD width=100% >             Select a View           </TD>         </TR>         <TR>           <TD >             <IMG src="/books/4/78/1/html/2//_layouts/images/blank.gif" width=1 height=1                  alt="">           </TD>         </TR>       </TABLE>       <SharePoint:ViewSelector runat="server"/> &nbsp;     </TD>     <TD style="padding-right: 2px;" class=ms-verticaldots>       &nbsp;     </TD>   </TR> </TABLE> <TABLE style="padding-top: 8px" class=ms-navframe CELLPADDING=0 CELLSPACING=0 BORDER=0 width=100% height=100%>   <TR>     <TD valign=top width=4px>       <IMG src="/books/4/78/1/html/2//_layouts/images/blank.gif" width=1 height=1 alt="">     </TD>     <TD valign=top ID=onetidSelectView class=ms-viewselect>       <SharePoint:RelatedTasks runat="server"/> &nbsp;     </TD>     <TD style="padding-right: 2px;" class=ms-verticaldots>       &nbsp;     </TD>   </TR> </TABLE> 




SharePoint 2003 Advanced Concepts. Site Definitions, Custom Templates, and Global Customizations
SharePoint 2003 Advanced Concepts: Site Definitions, Custom Templates, and Global Customizations
ISBN: 0321336615
EAN: 2147483647
Year: 2006
Pages: 64

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net