ONET.XML: Defining the Site Definition


Our site definition folder, MyFirstSiteDefinition, contains several resources that can be strung together to form various site definition templates. ONET.XML's main function is to glue these and other resources together to define one or more site definition templates. In our example, it exists on the physical file system in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\MyFirstSiteDefinition\XML folder (see Figure 2.4).

Figure 2.4. Site definition XML Explorer view.


As shown in Listing 2.3, ONET.XML is composed of one Project element, which in turn is composed of NavBars, ListTemplates, DocumentTemplates, BaseTypes, Configurations, and Modules elements. Each element has an extensive sub-element structure, which we detail in the following sections.

Listing 2.3. ONET.XML Structure

 <Project>   <NavBars/>   <ListTemplates/>   <DocumentTemplates/>   <BaseTypes/>   <Configurations/>   <Modules/> </Project> 

<Project>: Defining Settings That Apply throughout the Site Definition Template

The Project element exists at the top level and is used to define properties that are universal to the site. The allowable attributes are described in Table 2.4. The most popular attributes include AlternateCSS, AlternateHeader, and CustomJSUrl.

Table 2.4. <Project> Attributes

Attribute

Required

Type

Description

AlternateCSS

No

Text

Specifies an alternate CSS file to be used that overrides the default styles specified in OWS.CSS, which is located in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033\STYLES folder. The specified CSS must exist in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033\STYLES folder.

AlternateHeader

No

Text

Specifies an alternate header for the SharePoint site definition. The page must exist in the C:\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033 folder.

CustomJSUrl

No

Text

Defines a custom JavaScript file to be included with all the files associated with the site definition. The script must exist in the C:\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033 folder.

DisableWeb
DesignFeatures

No

Text

Disables specified Microsoft FrontPage editing features. Values are semicolon delimited and can be any collection of the following: wdfbackup, wdfrestore, wdfpackageimport, wdfpackageexport, wdfthemeweb, wdfthemepage, wdfnavigationbars, wdfnavigationview, wdfpublishview, wdfpublishselectedfile, wdfopensite, wdfnewsubsite.

ListDir

Yes

Text

According to the documentation, this specifies the folder where new lists are to be implemented. However, this has no real effect.

Title

Yes

Text

Defines the default name for the SharePoint site.


AlternateCSS: Using a Custom CSS

AlternateCSS is used to override the default SharePoint styles located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033\STYLES. It provides a quick and simple way to affect these styles throughout all pages in the site. However, it must reside in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033\STYLES folder.

Overriding various cascading style sheet styles is more powerful than it might first appear because almost every HTML element within Share-Point has a style associated with it. These style-specified elements include text, toolbars, icons, watermarks, tabs, and many other things. The CSS primarily facilitates changing the formatting or image associated with these elements.

AlternateHeader: Creating Your Own Header across All Site Definition Pages

The AlternateHeader attribute allows the substitution of the standard SharePoint headerthe top navigation menu bar. This alternate header is typically an ASPX page and must be located in the C:\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033 folder.

Fortunately, all the site's administration pages have ASP.NET code built in to render the custom header if it has been specified. By site administration pages, I mean all the pages that are mapped to the _layouts (C:\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS) virtual directory for the IIS web site. These include the list creation pages, site settings, site administration, and other administration pages.

The snippet in Listing 2.4 is taken from the CREATE.ASPX page and is representative of all the alternate header code written by Microsoft. By retrieving the context of the web site and then retrieving the AlternateHeader property, it can determine whether an AlternateHeader was specified through the <Project> element. If an alternate header was specified, it will be executed instead of painting the standard header.

Listing 2.4. Alternate Header Snippet Taken from CREATE.ASPX

 <%   string alternateHeader =            SPControl.GetContextWeb(Context).AlternateHeader;   if (alternateHeader == null || alternateHeader == "")   { %> <TR>   <TD COLSPAN=3 WIDTH=100%>   <!--Top bar-->   <table  border="0" cellspacing="0"          cellpadding="0"          width="100%">    <tr>     <td nowrap valign="middle"><img ID=onetidHeadbnnr0 alt="Logo"         src="/books/4/78/1/html/2//_layouts/images/logo.gif"></td>       <td class=ms-banner width=99% nowrap         valign="middle">         <!--webbot Bot="Navigation" startspan-->         <SharePoint:Navigation LinkBar runat="server"/>      </td>     <td class=ms-banner>&nbsp;&nbsp;</td>     <td nowrap class=ms-banner style="padding-right: 7px">         <SharePoint:PortalConnection runat="server" />     </td>    </tr>   </table>   </TD>  </TR> <%   }   else   {     Server.Execute(alternateHeader);   } %> 

Unfortunately, this code is not included in any of the Microsoft-provided site definitions. As such, AlternateHeader is designed primarily to customize only the header of administration pages, and not content pages. If you are going to pattern your site definition after Microsoft's site definition templates, you will need to modify every page you want to expose. Considering that there are about 100 pages in the STS site definition folder, it would require a non-trivial amount of time to modify each pageeven if you were only pasting code from the clipboard and saving.

More unfortunately, almost every ASPX page within the Microsoft-provided site definition templates has a different HTML structure. Thus, you cannot simply replace the top few lines of an ASPX page with your new and improved alternate header code and move on. You must tediously work this code into each page of your site definition.

For the moment, let's ignore the fact that the site definitions do not have the alternate header code embedded within them. Instead, let's go through the much simpler exercise of setting up an alternate header for the SharePoint administrative pages.

The first step is to add the AlternateHeader attribute to the Project element within ONET.XML. That change is shown in Listing 2.5.

Listing 2.5. ONET.XML Project Element Referencing an Alternate Header

 <Project Title="Team Web Site" ListDir="Lists"          xmlns:ows="Microsoft SharePoint"          AlternateHeader="MyFirstSiteDefinition_Header.aspx"> 

The second step is to create an alternate header page that is located in the C:\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033 folder. The name of the file should match the previously mentioned Project element's AlternateHeader attribute. That code is detailed in Listing 2.6.

Listing 2.6. MyFirstSiteDefinition_Header.ASPX Alternate Header Definition

 <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <TR>   <TD COLSPAN=3 WIDTH=100%>   <!--Top bar-->   <table border="0" cellspacing="0" cellpadding="0" width="100%">     <tr>       <td nowrap valign="middle" bgcolor="#1863bd">         <img ID=onetidHeadbnnr0 alt="Logo"              src="/books/4/78/1/html/2//_layouts/images/InformationHubLogo.png">       </td>     </tr>   </table>   <table  height="25pt" border="0"    cellspacing="0"    cellpadding="0" width="100%">      <td class=ms-banner width=99% nowrap        valign="middle">        &nbsp;&nbsp;        <!--webbot Bot="Navigation" startspan-->        <SharePoint:Navigation LinkBar runat="server"/>      </td>      <td class=ms-banner>&nbsp;</td>      <td nowrap class=ms-banner style="padding-right: 7px">        <SharePoint:PortalConnection runat="server" />      </td>    </tr>   </table>   </TD> </TR> 

To support the alternate header we just authored, we need to copy the InformationHubLogo.png image file to the C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\IMAGES folder.

After executing an IISReset and creating a new site with the modified site definition template, we see the result of our alternate header work as shown in Figure 2.5. The code we implemented for the alternate header was very simple. It displayed an Information Hub logo bar above the menu. However, it need not have been so simple. It could have used DHTML drop-down menus or just about any other HTML elements that the client browser can understand.

Figure 2.5. Using an alternate header.


Overriding SharePoint JavaScript Functions with CustomJSUrl

Another noteworthy attribute of the Project element is CustomJSUrl. CustomJSUrl provides a quick way to add a JavaScript file to every page in the site definition. One of its more interesting uses is to override specific functions within OWS.JSaffectionately known as SharePoint's client-side API. This technique takes the form of rewriting the selected OWS.JS functions in a custom JavaScript file. Although this method will result in two valid functions with the same name, the functions in the custom JavaScript file will be run instead of those within OWS.JS.

Of course, this override is a function of JavaScript and is not dependent on using CustomJSUrl. Therefore, you could replicate this functionality several ways. Instead of using CustomJSUrl, you could manually edit a SharePoint ASPX page or use the Content Editor web part on that page. Both methods enable you to inject a JavaScript function.

Adding Menu Items to the Drop-Down List Menus

In the following example, we add a menu item to the DHTML drop-down menus for SharePoint libraries and lists. When selected, this menu item will send an email link to the selected list or library item. The resulting document library menu is shown in Figure 2.6 and is representative of the list, picture library, and form library menus.

Figure 2.6. Email Link menu item added to document library.


Of the various ways to accomplish this task, the easiest is to use the CustomJSUrl attribute. The modified Project element in MyFirstSiteDefinition is shown in Listing 2.7.

Listing 2.7. ONET.XML Project Element Referencing a CustomJSUrl

 <Project Title="Team Web Site" ListDir="Lists"      xmlns:ows="Microsoft SharePoint"      AlternateHeader="MyFirstSiteDefinition_Header.aspx"      CustomJSUrl="_layouts/[%=System.Threading.Thread.CurrentThread. CurrentUICulture.LCID%]/OWS_MyFirstSiteDefinition.JS"> 

The first thing you might notice is that the [% and %] symbols delineates .NET code and appears to function as the <% and %> symbols do in ASP.NET. If you are like me, you might immediately think that you could use the full ASPX object model within ONET.XML. Unfortunately, that is not the case. Only the simplest ASPX code is allowed. Furthermore, this code's results are cached within the ASPX application and reused until that application has shut down. In the previous case, the code inserts the locale identifier (LCID). If you are using the default English version of SharePoint, your LCID should be 1033. Currently, Microsoft has defined over 200 LCIDs, which are documented on Microsoft's Global Development and Computing Portal (http://www.microsoft.com/globaldev/reference/lcid-all.mspx ).

The next tasks involve adding a menu item to the DHTML drop-down menu. Adding a menu item simply requires invoking the CAMOpt function (see Listing 2.8). However, that function must be passed the appropriate parameters and called from the appropriate place.

Listing 2.8. SharePoint CAMOpt JavaScript Function Declaration

 CAMOpt(m, strDisplayText, strAction, strImagePath); 

CAMOpt takes four parameters: the menu object, the display text string, the action string, and the image path string. The menu object defines the entire DHTML menu. The display text will be displayed in the menu. The action is a JavaScript action that will be performed when the item is selected. The image path specifies an icon for the menu item.

In our example, we will use the A tag's HREF attribute to enable emailing. Thus, strAction could use JavaScript's window object to create an email message as shown in Listing 2.9.

Listing 2.9. Example Use of CAMOpt's strAction Parameter

 // Mimic <a // href="mailto:jason@informationhub.com?subject=TestA&body=TestB"> strAction = 'window.navigate           (           "mailto:jason@informationhub.com?subject=TestA&body=TestB"              )'; 

The strAction parameter need not trigger client-side applications. It could also interact with SharePoint or other server applications. For instance, we could have called a custom ASPX page through window.navigate. This custom page could have taken subject, body, and other querystring parameters to send an email through the Share-Point server's SMTP resources instead of Microsoft Outlook. As such, these drop-down menus offer a tremendous amount of functionality.

Now the question is where to invoke CAMOpt. Because we want this functionality in both document libraries and lists, we need to extend the AddDocLibMenuItems and AddListMenuItems functions. It should come as no surprise that AddDocLibMenuItems adds items to the menu for document libraries and AddListMenuItems adds items to the menu for lists.

We need to copy the AddDocLibMenuItems and AddListMenuItems functions from OWS.JS to OWS_MyFirstSiteDefinition.JS. Both of these JavaScript files reside in the C:\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033 folder.

The only change to the AddListMenuItems and AddDocLibMenu-Items functions is to call AddEmailLinkToMenu immediately before exiting the function. AddEmailLinkToMenu is a function that we will need to write. The insertion of AddEmailLinkToMenu is shown in Listing 2.10.

Listing 2.10. Modified AddListMenuItems and AddDocLibMenuItems JavaScript Functions

 function AddListMenuItems(m, ctx) { . . .    AddEmailLinkToMenu (m, ctx); } function AddDocLibMenuItems(m, ctx) { . . .    AddEmailLinkToMenu (m, ctx); } 

Ultimately, AddEmailLinkToMenu (see Listing 2.11) appends an Email Link item to the menu using CAMOpt. However, the bulk of the work is determining the URL for the item and then formatting that information in a JavaScript statement that creates a new prepopulated mail message.

The more interesting aspects of this function include the use of ctx, CAMSep, and itemTable. The ctx object retrieves the virtual path to SharePoint's images directory, which maps to C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\IMAGES. CAMSep is a function that appends a separator to the end of the menu. The itemTable object defines the table row of the selected library or list item.

Listing 2.11. AddEmailLinkToMenu JavaScript Function Definition

 function AddEmailLinkToMenu(m, ctx) {   var strDisplayText = "Email Link";   var strAction = "";   var strImagePath = ctx.imagesPath + "SendTo.gif";   var strURL = "";   //Using regular expressions, find the URL of the item   var strItemHTML = itemTable.innerHTML;   var regexURL = /href="([^"]*)"/;   var mURL = regexURL.exec(strItemHTML);   if(mURL != null)     strURL = mURL[1];   //Encode white space with %20   var regexEncode = / /;   strURL = strURL.replace(regexEncode, "%20") ;   //Only add menu item if a valid URL exists   if (strURL != "")   {     strSubject = "Please review " + strURL;     strMessage = "Please review the following item: " + strURL;     strAction = 'window.navigate("mailto: ?subject='       + escape(strSubject) + '&body=' + escape(strMessage) + '")';     //Add Separator     CAMSep(m);     //Add Menu Item     CAMOpt(m, strDisplayText, strAction, strImagePath);   } } 

An example itemTable.innerHTML is shown in Listing 2.12. Although this was taken from a document library, it is representative of all lists and libraries. In the AddEmailLinkToMenu function, we used regular expressions to find the A tag's hrEF attribute. The URL referenced by hrEF was passed into the email message.

Listing 2.12. Example Value of itemTable.innerHTML from a Document Library

 <TABLE class=ms-selectedtitle onmouseover=OnItem(this) height="100%"        cellSpacing=0 SourceUrl="" COUId="" FSObjType="0"        DocIcon="icgen.gif||" FileType="dat" HTMLType=""        FileDirRef="MyFirstSiteDefinition/DL"        ServerUrl="/MyFirstSiteDefinition/DL/Header Information.dat"        Item CTXName="ctx1">   <TBODY>     <TR>       <TD class=ms-vb width="100%">         <A onfocus=OnLink(this)          onclick="DispDocItemEx(this,'FALSE','FALSE','FALSE','')"          href="http://Moose:81/MyFirstSiteDefinition/DL/          HeaderFile.dat">            HeaderFile         </A>         <IMG alt=New src="/books/4/78/1/html/2//_layouts/1033/images/new.gif"/>       </TD>       <TD class=ms-menuimagecell style="VISIBILITY: visible">         <IMG style="VISIBILITY: visible" alt=Edit              src="/books/4/78/1/html/2//_layouts/images/downarrw.gif" width=13/>       </TD>     </TR>   </TBODY> </TABLE> 

Defining and Rendering Navigation with the <NavBars>

NavBars specify the navigation bars that are rendered by the SharePoint Navigation web control. Listing 2.13 details the top navigation bar defined in ONET.XML. The results of this listing are shown in Figure 2.7.

Listing 2.13. Default ONET.XML Top Navigation Bar

[View full width]

 <Project Title="Team Web Site" ListDir="Lists"          xmlns:ows="Microsoft SharePoint">   <NavBars>     <NavBar Name="SharePoint Top Navbar"          Separator="&amp;nbsp;&amp;nbsp;&amp;nbsp;"          Body="&lt;a ID='onettopnavbar#LABEL_ID#' href='#URL#'          accesskey='J'&gt;#LABEL#&lt;/a&gt;"          docEmphStrong">1002">     <NavBarLink Name="Documents and Lists"                 Url="_layouts/[%=System.Threading.Thread.CurrentThread.CurrentUICulture .LCID%]/viewlsts.aspx">     </NavBarLink>     <NavBarLink Name="Create"                 Url="_layouts/[%=System.Threading.Thread.CurrentThread.CurrentUICulture .LCID%]/create.aspx">     </NavBarLink>     <NavBarLink Name="Site Settings"                 Url="_layouts/[%=System.Threading.Thread.CurrentThread.CurrentUICulture .LCID%]/settings.aspx">     </NavBarLink>     <NavBarLink Name="Help"                 Url='javascript:HelpWindowKey("NavBarHelpHome")'>     </NavBarLink>   </NavBar> . . . 

Figure 2.7. Default top navigation defined in ONET.XML.


Navigation links can be added, modified, or deleted by modifying the appropriate NavBars section of ONET.XML. For instance, Listing 2.14 now includes an additional NavBarLink to Information Hub. The resulting navigation bar is shown in Figure 2.8.

Listing 2.14. Modified ONET.XML Top Navigation Bar

[View full width]

 <Project Title="Team Web Site" ListDir="Lists"          xmlns:ows="Microsoft SharePoint">   <NavBars>     <NavBar Name="SharePoint Top Navbar"             Separator="&amp;nbsp;&amp;nbsp;&amp;nbsp;"             Body="&lt;a ID='onettopnavbar#LABEL_ID#' href='#URL#'             accesskey='J'&gt;#LABEL#&lt;/a&gt;"             hdocEmphStrong">1002">h     <NavBarLink Name="Documents and Lists" Url="_layouts/[%=System.Threading.Thread.CurrentThread.CurrentUICulture.LCID%]/viewlsts.aspx">     </NavBarLink>     <NavBarLink Name="Create"                 Url="_layouts/[%=System.Threading.Thread.CurrentThread.CurrentUICulture .LCID%]/create.aspx">     </NavBarLink>     <NavBarLink Name="Site Settings"                 Url="_layouts/[%=System.Threading.Thread.CurrentThread.CurrentUICulture .LCID%]/settings.aspx">     </NavBarLink>     <NavBarLink Name="Information Hub"                 Url='javascript:void(window.open(                      "http://www.informationhub.com",                      "InformationHub"))'>     </NavBarLink>     <NavBarLink Name="Help"                 Url='javascript:HelpWindowKey("NavBarHelpHome")'>     </NavBarLink>   </NavBar> . . . 

Figure 2.8. Modified top navigation defined in ONET.XML.


One of the first things you might have noticed is that Home is not defined in the navigation bar. That is because it is handled in another section of ONET.XML. That link is defined in the File section of ONET.XML and is more fully explained later in Table 2.11.

Complex changes to the top navigation are not simple to implement. Although it is tempting to believe that the ASP.NET code embedded within the NavBarLink elements could be used as a mechanism for dynamic menus, this is not the case.

As mentioned earlier, the top navigation is rendered with a Share-Point web control. The SharePoint web control retrieves the NavBar element with an ID defined in the LinkBarID. In the case of our site definition, this ID is 1002, so the web control retrieves the navigation as explained previously. Additionally, this ID must also be referenced in the appropriate Modules sectionwhich we cover later in this chapter.

Listing 2.15. SharePoint Navigation Web Control to Render Top Navigation

 <!--webbot bot="Navigation"       S-Type="sequence"       S-Orientation="horizontal"       S-Rendering="html"       S-Btn-Nml="<a ID='onettopnavbar#LABEL_ID#' href='#URL#'                     accesskey='J'>#LABEL#</a>"       S-Btn-Sel="<a ID='onettopnavbar#LABEL_ID#' href='#URL#'                     accesskey='J'>#LABEL#</a>"       S-Btn-Sep="&amp;nbsp;&amp;nbsp;&amp;nbsp;"       B-Include-Home="FALSE"       B-Include-Up="FALSE"       S-Btn-Nobr="FALSE"       U-Page="sid:1002"       S-Target startspan -->       <SharePoint:Navigation LinkBar runat="server"/> <!--webbot bot="Navigation" endspan --> 

<ListTemplates>: Specifying the Allowed Lists and Libraries

ListTemplates defines the documents and lists as well as their properties for the site definition. Only the list types specified (through the ListTemplate elements) can be created for the site. For example, the XML specified in Listing 2.16 only enables document libraries to be created. This is further evidenced by Figure 2.9, which shows Document Libraries as the only list type.

Listing 2.16. ONET.XML ListTemplates Definition That Allows Only Document Libraries

 <ListTemplates>   <ListTemplate Name="doclib" DisplayName="Document Library"     Type="101" BaseType="1" OnQuickLaunch="TRUE"     SecurityBits="11"     Description="Create a document library when you have a                  collection of documents or other files that you                  want to share. Document libraries support features                  such as sub-folders, file versioning, and check-in/                  check-out."     Image="/_layouts/images/itdl.gif" DocumentTemplate="101">   </ListTemplate> </ListTemplates> 

Figure 2.9. List Creation page with only Document Libraries allowed.


Although other choices might appear on the page, such as Import Spreadsheet, you can only create list types listed in your ListTemplates section. In the current example, if you try to import a spreadsheet, it will fail because Import Spreadsheet is dependent on a Custom List typewhich isn't specified in ONET.XML.

When restricting the available list types, be mindful that dependencies on these lists can trigger an error. For instance, both the Configuration and Modules sections can reference a list type that you have not listedhence denying its availability. If that happens, SharePoint will not be able to create your site, and the user will be presented with an error. If you truly want to create a default document library, such as Shared Documents, but do not want to allow the user to create other lists, you should consider using the Hidden attribute for ListTemplate. All the ListTemplate attributes are shown in Table 2.5.

Table 2.5. <ListTemplate> Attributes

Attribute

Required

Type

Description

BaseType

Yes

Integer

This specifies the schema for the list. That schema is defined in the BaseTypes section of ONET.XML.

Catalog

No

Boolean

If trUE, indicates that the list is of a special catalog type. Thus, the list type is a Site Template Gallery, List Template Gallery, or Web Part Gallery.

Default

No

Boolean

According to the documentation, a trUE value indicates that new SharePoint sites will include this list. However, it has no effect.

Description

No

Text

Provides a description for the list template that shows up on the Create and ViewLists pages.

DisplayName

Yes

Text

Specifies a friendly name for the list template.

DocumentTemplate

No

Integer

Implemented only for document libraries. This is the default file that is opened when the user clicks the New Document button in the document library's AllItems page.

DontSaveInTemplate

No

Boolean

If trUE, the content of the list will not be saved when creating a custom template.

Hidden

No

Boolean

If trUE, the list type will not be shown on the Create page, so the user will not be able to create that type of list.

HiddenList

No

Boolean

If trUE, the list instance created from this list template will be hidden from the user.

Image

No

URL

Associates an icon with the list. This icon is only specified on the Create page. The icon on the individual list page (for example, /Lists/Discussions/AllItems.aspx) is actually hard coded in the ASPX and is not affected by changing this value.

MultipleMtgDataList

No

Boolean

If trUE, indicates that the list is within a Meeting Workspace site and contains data for multiple meeting instances.

MustSaveRootFiles

No

Boolean

This is only intended for internal Microsoft use.

Name

Yes

Text

This specifies the internal name for the list template. This should be only alphanumeric text with no spaces or other special characters.

OnQuickLaunch

No

Boolean

If trUE, the list instance will be placed on the Quick Launch bar if created through the <Configurations> element in ONET.XML.

Path

No

Text

Specifies the name of the site definition that defines the list schema. This would be helpful if you wanted to externally define (in another site template) the schema. The Meeting Workspaces make use of this to reference schemas in the STS site definition.

RootWebOnly

No

Boolean

If trUE, indicates that the list created only exists at the root web site of the site collection. This is used for special lists, such as a Web Part Gallery, that need to be defined only once and not for each instance of a site.

SecurityBits

No

Text

For non-document libraries, this specifies the read and write security. This maps to tp_ReadSecurity and tp_WriteSecurity columns in the Lists database table.

Type

No

Integer

Specifies a unique key to identify the list template. This is referenced when creating the list in the <Configurations> element. SharePoint defines the following list types: 100-Generic list, 101-Document Library, 102-Survey list, 103-Links list, 104-Announcement list, 105-Contact lists, 106-Event lists, 107-Task lists, 108-Discussion lists, 109-Picture Libraries, 110-Data sources lists, 111-Site Template Gallery, 113-Web Part Gallery, 114-List Template Gallery, 115-XML Form library, 120-Custom grid for a list, 200-Meeting series list, 201-Meeting agenda list, 202-Meeting attendees list, 204-Meeting decisions list, 207-Meeting objectives list, 210-Meeting text box, 211-Meeting things to bring list, 212-Meeting workspace pages list, 1100-Issue tracking list, 2002-Personal document library, and 2003-Private document library. You should not change the values of these types. You should also not create another list template with any number less than 3000.

Unique

Yes

Boolean

If trUE, a list of this type can only be created at site creation, and not through the Create page or the object model. Therefore, this effectively sets the Hidden attribute to trUE. Like RootWebOnly, this attribute is used by the galleries.


Let's examine the use of Hidden and HiddenList. Let's assume that our site definition will create a document and image librarywhich will be discussed in the Configurations section. If we were also to modify our site definition as specified in Listing 2.17, we would make all instances of document libraries hidden and make the picture library list type hidden. This is evidenced by the screenshots in Figure 2.10, Figure 2.11, and Figure 2.12.

Listing 2.17. ONET.XML ListTemplate Definitions

 <ListTemplate Name="doclib" DisplayName="Document Library"      HiddenList="TRUE" Type="101" BaseType="1" OnQuickLaunch="TRUE"      SecurityBits="11"      Description="Create a document library when you have a                   collection of documents or other files that you                   want to share.                   Document libraries support features such as                   sub-folders, file versioning, and check-in/                   check-out."      Image="/_layouts/images/itdl.gif" DocumentTemplate="101"> </ListTemplate> <ListTemplate Name="imglib" DisplayName="Picture Library"      Hidden="TRUE"      Type="109" BaseType="1" OnQuickLaunch="TRUE" SecurityBits="11"      Description="Create a picture library when you have pictures                   you want to share. Picture libraries provide                   special features for managing and displaying                   pictures, such as thumbnails, download options,                   and a slide show."      Image="/_layouts/images/itil.gif"      DocumentTemplate="100"> </ListTemplate> 

Figure 2.10. The hidden list template of Picture Libraries does not appear on the Create page.


Figure 2.11. Shared Documents as a hidden list that does not appear to exist.


Figure 2.12. Shared Documents as a hidden list that is still navigable.


In Figure 2.10, we see that Document Libraries can be created. Furthermore, we see that even though Picture Libraries are a valid list type, they cannot be created through the Create page. This is because the Hidden attribute has been set to trUE for the list template.

Because the document library list template is set with the Hidden list attribute, all instances of that list type will be hidden from the userbut they will exist. Figure 2.11, which shows all documents and lists, is noticeably vacant of our Shared Documents document library. However, it does existas shown in Figure 2.12.

You might have noticed the DocumentTemplate attribute. If you are creating a document library, you should define the document template on which all new documents will be based. You reference this template through the DocumentTemplate attribute. The document template that you reference here is defined in the DocumentTemplates section.

<DocumentTemplates>: Specifying the Default New Document for a Document Library

Have you ever wondered how the New Document buttonas shown in Figure 2.13knows what document to create? How does it know to use a Word, Excel, HTM, or other template? Have you ever wanted to customize that fileperhaps with your organization's standard header? If so, you will be happy to know that all this is controlled through the DocumentTemplates element.

Figure 2.13. Document Library Toolbar.


If a user creates a new document library, the user specifies the template at the document library's time of creation. However, if it needs to be created at site creationas part of the site definitionit is mapped to the desired DocumentTemplate element. In turn, this DocumentTemplate element specifies a template file that resides as a physical file in your site definition folder.

To specify the default new document for a document library created during site creation, the ListTemplate/@DocumentTemplate attribute is mapped to the matching DocumentTemplate/@Type attribute. In the ListTemplates code snippet shown previously in Listing 2.17, you will notice that the document library's DocumentTemplate attribute is specified as 101. In the DocumentTemplates element detailed in Listing 2.18, you will notice that the matching element with a type of 101 is a Microsoft Word file. That is how the document library list knows to create a Word document when the user clicks New Document.

Listing 2.18. ONET.XML DocumentTemplates Definition

 <DocumentTemplates>   <DocumentTemplate Name="" DisplayName="None" Type="100"        Default="FALSE" Description="This document library will not                 use templates.">   </DocumentTemplate>   <DocumentTemplate DisplayName="Microsoft Office Word document"       Type="101" Default="TRUE"       Description="A blank Microsoft Office Word document.">     <DocumentTemplateFiles>       <DocumentTemplateFile Name="doctemp\word\wdtmpl.doc"           TargetName="Forms/template.doc" Default="TRUE"/>       </DocumentTemplateFiles>     </DocumentTemplate> . . . 

The DocumentTemplate element is defined in Table 2.6. All the attributes defined in the table are fairly straightforward. The only attribute that stands out is Default. It specifies the default document template to be used when creating a document library. This template is preselected when the user visits the New Document Library pageas shown in Figure 2.14.

Table 2.6. <DocumentTemplate> Attributes

Attribute

Required

Type

Description

Default

No

Boolean

If trUE, this document template is selected as the default in the drop-down menu on the New Document Library page. There should only be one DocumentTemplate element with a value of trUE in all of ONET.XML.

Description

No

Text

Specifies a description for the document template.

DisplayName

Yes

Text

Specifies the display name of the document template.

Name

No

Text

Specifies an internal name for the document template.

Path

No

Text

Specifies the name of the site definition to which the document template belongs. This is helpful if you want to externally define (in another site template) the document template file.

Type

Yes

Integer

A unique ID/Key for the document template. This is what the ListTemplate's DocumentTemplate references.

XMLForm

No

Boolean

If TRUE, the document template applies to a form library.


Figure 2.14. Creating a new document library.


The DocumentTemplateFile element specifies the actual file to be used. As alluded to earlier, this file could be of any type and could be seeded with some custom content. Such would be the case with a Word document that has the corporate stationary embedded in it.

The DocumentTemplateFile/@Name attribute specifies the relative path to the file within the site definition. Listing 2.18 specifies the Word document template as doctemp\word\wdtmpl.doc relative to your site definition folder. In our example, this would map to C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\MyFirstSiteDefinition\doctemp\word\wdtmpl.doc.

Conversely, the TargetName attribute creates a hidden virtual path to this file in the document library. In the Word document template case, it is Forms/template.doc. You can verify this by going to any document library that uses this document template, switching to the Explorer view, and navigating into the Forms folder to see template.doc. Thus, when the user clicks the New Document button, the user is actually loading the customized Forms/template.doc file.

Table 2.7. <DocumentTemplateFile> Attributes

Attribute

Required

Type

Description

Default

No

Boolean

If trUE, the document template file will be the default file. Practically speaking, you should have only one file for each DocumentTemplate element. That one file will also be the default file.

Name

Yes

Text

The physical relative path to the file within the site definition.

TargetName

No

Text

The virtual path to the file within the document library.


<BaseTypes>: The Foundation for List and Library Definitions

BaseTypes define the schema for the lists and libraries (see Listing 2.19). As mentioned earlier, the list base type is specified through the ListTemplate/@BaseType attribute. This attribute actually references the Base-Type/@Type attribute. BaseType attributes are defined in Table 2.8.

Listing 2.19. ONET.XML BaseType 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>       <Field ColName="tp_Created" Hidden="TRUE"              ReadOnly="TRUE" Type="DateTime" Name="Created"              DisplayName="Created Date"              StorageTZ="TRUE"></Field>       <Field ColName="tp_Author" ReadOnly="TRUE" Type="User"              List="UserInfo" Name="Author"              DisplayName="Created By" ></Field>       <Field ColName="tp_Modified" Hidden="TRUE"              ReadOnly="TRUE" Type="DateTime" Name="Modified"              DisplayName="Last Modified"               StorageTZ="TRUE"></Field>       <Field ColName="tp_Editor" ReadOnly="TRUE" Type="User"              List="UserInfo" Name="Editor"              DisplayName="Modified By" ></Field>       <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> . . . 

Table 2.8. <BaseType> Attributes

Attribute

Required

Type

Description

Image

No

Text

Specifies the URL to an icon representing this list type. Typically, this value will be overwritten by the list (ListTemplate\@Image).

Title

No

Text

The title/name for the list schema.

Type

No

Integer

This is a unique ID for the list schema. SharePoint defines five built-in base types: (0) Custom List, (1) Document Library, (2) Not Used, (3) Discussion, (4) Survey, and (5) Issue.


The snippet in Listing 2.19 details part of the schema definition for document libraries. Because the functionality of lists is bound to their schemas, you should never remove field elements. For instance, if you removed the column that stores the name of the person who checked out a file, the built-in functionality for document libraries would suddenly break.

There are five base types in SharePoint. Unfortunately, other base list types cannot be added. However, the custom list type can be augmented to provide the functionality desired. This is done through modifying a SCHEMA.XML, which we cover more fully in Chapter 3.

SCHEMA.XML is designed to extend the functionality of the Base-Type element. In fact, the MetaData element is used in both ONET.XML and SCHEMA.XML. In ONET.XML, MetaData defines the base fields for a list. In SCHEMA.XML, MetaData can define additional fields, views, toolbars, forms, and a default description.

It is worth mentioning that the FLDTYPES.XML file defines the allowable Field types. Thus, Field/@Type must be of a value defined within FLDTYPES.XML. FLDTYPES.XML should not be modified.

We also recommend that you do not modify the BaseTypes section in ONET.XML. You should be able to modify SCHEMA.XML to effect any changes that modifying the BaseType would accomplish.

<Configurations>: Defining the Site Definition Templates

A site definition can contain multiple flavors of templateswhich are referred to as site definition templates. In fact, all eight default WSS templates (Team Site, Blank Site, Document Workspace, Basic Meeting Workspace, Blank Meeting Workspace, Decision Meeting Workspace, Social Meeting Workspace, and Multipage Meeting Workspace) are created from only two site definitions. The STS site definition contains Team Site, Blank Site, and Document Workspace definitions. The MPS site definition contains the Basic Meeting Workspace, Blank Meeting Workspace, Decision Meeting Workspace, Social Meeting Workspace, and Multipage Meeting Workspace.

The snippet in Listing 2.20 details a few site definition templates in the MyFirstSiteDefinition site definition that we created earlier. As you might recall, we simply copied the STS site definition and therefore inherited all the templates from STS. So now you are thinking, if I have inherited all these templates defined in ONET.XML, why aren't they showing up on the Template Selection page when I create a new site? Well, the WEBTEMP.XML file controls what shows up on that page. Thus, you could have multiple site definition templates defined in ONET.XML but only a subset of them exposedwhich is the case here.

Listing 2.20. ONET.XML Configuration for Team Site

 <Configurations>   <Configuration  Name="NewWeb"/>   <Configuration  Name="Default">     <Lists>       <List Title="Shared Documents"             Url="Shared Documents"             QuickLaunchUrl="Shared Documents/Forms/AllItems.aspx"             Type="101" />       <List Title="General Discussion"             Url="Lists/General Discussion"             QuickLaunchUrl="Lists/GeneralDiscussion/AllItems.aspx"             Type="108" />       <List Title="Announcements"             Type="104"             Url="Lists/Announcements" />       <List Title="Links"             Type="103"             Url="Lists/Links" />       <List Title="Contacts"             Url="Lists/Contacts"             QuickLaunchUrl="Lists/Contacts/AllItems.aspx"             Type="105" />       <List Title="Events"             Type="106"             Url="Lists/Events" />       <List Title="Tasks"             Url="Lists/Tasks"             QuickLaunchUrl="Lists/Tasks/AllItems.aspx"             Type="107" />       <List Title="Site Template Gallery"             Type="111"             Url="_catalogs/wt"             RootWebOnly="TRUE" />       <List Title="Web Part Gallery"             Type="113"             Url="_catalogs/wp"             RootWebOnly="TRUE" />       <List Title="List Template Gallery"             Type="114"             Url="_catalogs/lt"             RootWebOnly="TRUE" />     </Lists>     <Modules>       <Module Name="Default"/>       <Module Name="WebPartPopulation"/>     </Modules>   </Configuration>   <Configuration  Name="Blank">     <Lists>       <List Title="Site Template Gallery" Type="111"             Url="_catalogs/wt" RootWebOnly="TRUE" />       <List Title="Web Part Gallery" Type="113"             Url="_catalogs/wp" RootWebOnly="TRUE" />       <List Title="List Template Gallery" Type="114"             Url="_catalogs/lt" RootWebOnly="TRUE" />     </Lists>     <Modules>       <Module Name="DefaultBlank"/>       <Module Name="WebPartPopulation"/>     </Modules>   </Configuration>  .  .  . </Configurations> 

In our example WEBTEMP.XML file, we are only referencing the Configuration with an ID of 0 despite the multiple other IDs available in ONET.XML. Irrespective of WEBTEMP.XML, each Configuration element specified in ONET.XML can define several List and Module elements.

The Module elements define files that are mapped into the site definition template. We will save our discussion of Modules for the next section. Furthermore, we have already defined the Configuration element in our previous discussion on WEBTEMP.XML, so we will not duplicate that discussion here.

The List elements define the various lists that are created when the site definition template is applied. The seven user lists specified in the Lists element for Configuration ID 0 are shown in a newly created site with the template in Figure 2.15. The other three lists specifiedSite Template Gallery, Web Part Gallery, and List Template Galleryare special list types that are not exposed to the user through the Document and Lists page shown in Figure 2.15. As you might recall from Chapter 1, "Custom Templates," the Site Template Gallery is a document library for storing custom site templates, and the List Template Gallery is a document library for storing custom list templates. The Web Part Gallery stores WebPart DWP files. When you define your own List element, you will probably specify at least QuickLaunchURL, RootWebOnly, Title, Type, and Url. The complete set of List attributes is described in Table 2.9. It is worth noting that SCHEMA.XML can override the settings within ONET.XML. Thus, if you change the value here and are confused about why nothing happened, check SCHEMA.XML to see whether it is overriding your settings.

Figure 2.15. The seven user lists created by our site definition.


Table 2.9. <List> Attributes

Attribute

Required

Type

Description

BaseType

No

Integer

This specifies the schema for the list. That schema is defined in the BaseTypes section of ONET.XML.

Default

No

Boolean

If trUE, the list will be created at site creation, and if FALSE, it will not be created at site creation. However, the list is created regardless of the setting.

Direction

No

Integer

This specifies the direction of the reading order for the list. 0 is left to right, and 1 is right to left. Contrary to Microsoft documentation, it is required in neither ONET.XML nor SCHEMA.XML.

DisableAttachments

No

Boolean

If trUE, attachments cannot be added to the list.

EventSinkAssembly

No

Text

This specifies the strong named assembly that hooks into Share-Point's event model for the document library.

EventSinkClass

No

Text

This specifies the class within the EventSinkAssembly that will respond to the SharePoint events.

EventSinkData

No

Text

Specifies an arbitrary string that is passed to your custom event handler. It is left to the discretion of your custom handler to handle events differently depending on the value of this string.

Name

No

Text

Specifies the internal name for the list.

OrderedList

No

Boolean

If trUE, asks an additional question in the Edit View page: "Allow users to order items in this view?"

PrivateList

No

Boolean

If trUE, does not inherit permissions of the site and allows only the web designer role to access the list.

QuickLaunchUrl

No

Text

If specified, the list will be featured on the Quick Launch bar of the site's home page with the specified URL.

RootWebOnly

No

Boolean

If trUE, the list should only exist at the root site collection level, and there should not be separate instances for each site.

ThumbnailSize

No

Integer

This defines the pixel width of thumbnails in picture libraries.

Title

Yes

Text

Specifies the name that the user sees for this list.

Type

Yes

Integer

Specifies the list template that should be used to create this list. This is specified by referencing the ListTemplate/@Type attribute. SharePoint's default types are covered in Table 2.5.

Url

No

URL

This specifies the virtual path of the site for which the list will be created.

URLEncode

No

Boolean

If TRUE, the URL will be encoded.

VersioningEnabled

No

Boolean

If trUE, Versioning will be enabled by default.

WebImageHeight

No

Integer

When the list is a picture library, this specifies the pixel height for an image in the library.

WebImageWidth

No

Integer

When the list is a picture library, this specifies the pixel width for an image in the library.


If we wanted to create additional lists, we would have simply added another List element with the appropriate attribute settings. If we want to limit the lists that are created, we would remove the undesired List elements.

If the QuickLaunchURL attribute has been specified, the specified URL is listed on the Quick Launch bar on the site's home page. You can specify any URLincluding one that does not link to the list. However, the Quick Launch URL can be reset to the correct one. This will happen if the user modifies the list's general settings to display it on the Quick Launch baras shown in Figure 2.16. This action will erase the URL you have specified as part of the List attribute and will replace it with the default All Items view.

Figure 2.16. Quick Launch settings on the List General Settings page.


The RootWebOnly attribute specifies that the list should not actually exist at the site level. Instead, it should exist at the root web of the site collection, and there should not be an instance at every site. A good example of a list that should exist only at the root web is the Web Part Gallery list. Obviously, you don't need to duplicate this list at every site. With that said, this attribute presumes that the root web list specified already exists. Thus, make sure the list exists before you use this setting.

Lastly, URL specifies the virtual path to link to your list. If the Contacts list URL was modified from Lists to MyLists, as shown in Listing 2.21, then the virtual path to the Contacts list would change. Therefore, the URL to the list would be /MyFirstSiteDef/MyLists/MyContacts/AllItems.aspx, which is shown in Figure 2.17.

Listing 2.21. ONET.XML List Definition

 <List Title="Contacts" Url="MyLists/MyContacts" QuickLaunchUrl="MyLists/MyContacts/AllItems.aspx" Type="105" /> 

Figure 2.17. The URL changes in List are reflected here.


<Modules>: Grouping Elements of a Site Definition Together to Use within Configurations

Modules are simply functional file groups. As explained in the previous section, when you select a specific site definition template, you are actually selecting a specific Configuration element in ONET.XML. That Configuration element inevitably specifies several modules. The files specified in those modules are then deployed to the newly created site. Module attributes are defined in Table 2.10.

Table 2.10. <Module> Attributes

Attribute

Required

Type

Description

List

No

Integer

Specifies the list type as defined in the ListTemplates section earlier in ONET.XML.

Name

Yes

Text

Defines an identifier by which the module can be referenced.

Path

No

Text

Specifies the physical relative folder path from which to retrieve the file.

RootWebOnly

No

Boolean

If TRUE, this signifies that the modules are installed at the top-level web site (of the site collection).

Url

No

Text

Specifies the virtual relative folder path in which to place the file.


Module Basics

The module in Listing 2.22 defines two pictures to be included with a site definition. Although the Name, Url, and Path attributes all have a value, they each have a different function.

Listing 2.22. ONET.XML Simple Module Definition

 <Module Name="Images" Path="images" Url="images">       <File Url="InformationHub.png" />       <File Url="JasonNadrowski.jpg" /> </Module> 

The Name attribute specifies an identifier that can be used to reference this specific module. This would be used to reference this module from the Configuration section in ONET.XML as we discussed in the previous section. Name could be something very cryptic because it is never exposed to the user.

The Path attribute specifies a folder relative to the site definition template's physical path. As shown in the Explorer screenshot in Figure 2.18, the images path is a child folder of the MyFirstSiteDefinition site definition and exists on the server's local physical hard drive.

Figure 2.18. Physical path as defined by the Path attribute.


Conversely, the Url attribute specifies a virtual path relative to an instance of the site. In the example shown in Figure 2.19, the image is mapped from the database to images virtual folder. Keep in mind that this is not an absolute path. It is a virtual path off an instance of the site definition template. Therefore, you will need to think a little more carefully when referencing these images from your various pages within the site definition because the image might or might not be available on /MyFirstSiteDef/Images/InformationHub.png or /MyFirstSiteDef/Subsite1/Images/InformationHub.png.

Figure 2.19. Virtual path as defined by the Url attribute.


Both the Path and Url attributes can support a syntax of a multiple-level folder structure. For instance, a Url value of "images/informationhub/2005" could just as easily have been specified in Listing 2.22.

Fortunately, there is no need to build a multiple-level virtual path with multiple parent modules (for example, Url="images", Url="images/informationhub") as you would with a physical folder structure. The module files are actually mapped in the database, and their entire path is stored with them. The somewhat negative aspect of this is that you cannot browse their parent folders. When you try to browse to the images folder, you get a 404 error (see Figure 2.20), which gives the user the impression that there are no other child items herewhich is not the case. In our current scenario, there are two images within the images folder (JasonNadrowski.jpg and InformationHub.png).

Figure 2.20. Images parent folder does not exist even though it contains pictures.


From a best practice standpoint, you should match your physical path to the virtual Url as we have done with images. Making your virtual and physical paths the same helps to minimize confusion when someone new looks at the site definition or when you revisit it.

The File element is the only child element that a module can have. The File element is described in Table 2.11.

Table 2.11. <File> Attributes

Attribute

Required

Type

Description

Name

No

Text

Defines an identifier by which the File element can be referenced.

NavBarHome

No

Boolean

If trUE, the file will be referenced by the navigation bar home link.

Type

No

Text

If Ghostable, the file will be cached. If GhostableInLibrary, the file will be cached as part of a list whose base type is Document Library.

Url

Yes

Text

Specifies the relative physical path on the server's disk in relation to the Module's Path attribute.


In Listing 2.22, we only use the File element's Url attribute. This attribute name is a bit confusing because it is more in line with the Module's Path attribute than with the module's Url attribute. It defines the physical path relative to the module's Path attribute. We had simply specified the filenames with no path in the file's Url attribute because they resided within the images folder.

Specifying true for the NavBarHome attribute signifies that Home on the top navigation bar (see Figure 2.21) will be linked to the File element. Because that navigation bar is used throughout the entire site, it is invalid to have more than one link for Home. Although you can have multiple File elements that have their NavBarHome attribute set to trUE within all of ONET.XML, you can only have one File element with its NavBarHome attribute set to trUE within a single Configuration element.

Figure 2.21. Top navigation bar.


SharePoint will cache most file types (GIF, JPG, PNG, etc.) when referenced with the File element, but ASPX files will not be cached. Thus, changes to an ASPX file will be immediately reflected in a site without an IISReset. However, changes to other file types, such as a JPG file, will not be reflected until SharePoint is restarted through an IISReset.

Advanced Module Concepts: Views, WebParts, and Navigation Bars

Now let's look at a little more intricate use of the Module element. The code snippet in Listing 2.23 details a Module for deploying the DEFAULT.ASPX file. In this listing, the File element has three additional child elements: NavBarPage, AllUsersWebPart, and View.

Listing 2.23. ONET.XML Complex Module Definition

 <Module Name="Default" Url="" Path="">   <File Url="default.aspx" NavBarHome="True">     <View List="104" BaseView WebPartZone/>     <View List="106" BaseView WebPartZone           WebPartOrder="2"/>     <AllUsersWebPart WebPartZone WebPartOrder="1">       <![CDATA[         <WebPart             xmlns="http://schemas.microsoft.com/WebPart/v2"             xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image">           <Assembly>             Microsoft.SharePoint, Version=11.0.0.0,             Culture=neutral, PublicKeyToken=71e9bce111e9429c           </Assembly>           <TypeName>             Microsoft.SharePoint.WebPartPages.ImageWebPart           </TypeName>           <FrameType>None</FrameType>           <Title>Site Image</Title>           <iwp:ImageLink>/_layouts/images/homepage.gif</iwp:ImageLink>         </WebPart>       ]>     </AllUsersWebPart>     <View List="103" BaseView WebPartZone           WebPartOrder="2"/>     <NavBarPage Name="Home"  Position="Start"></NavBarPage>     <NavBarPage Name="Home"  Position="Start">     </NavBarPage>   </File> </Module> 

The NavBarPage element interacts with the navigation bar that we defined in the NavBars section. You might recall that although we defined navigation items for Documents and Lists, Create, Site Settings, and Help, we didn't define a Home element. You can add items to the top navigation bar in the Module.

The first NavBarPage elementwith an ID of 1002binds DEFAULT.ASPX to the top navigation bar we defined within the NavBars section. It is no coincidence that the ID of the NavBarPage element (Listing 2.23) matches the ID of the NavBar element (Listing 2.13). If it didn't, SharePoint would become confused.

The second NavBarPage elementwith an ID of 0adds Home to the top navigation bar. Additional Modules could be added to the top navigation bar, just as DEFAULT.ASPX was mapped to home, with the aid of NavBarPage. Those additional modules would need a unique ID for their NavBarPage element and their position. Their placement on the navigation bar would be controlled by the Position attribute. Position can be Start, End, or a number.

AllUsersWebPart enables you to place a named web part on the web part page. In our example, we place the Image web part on the web part page. We just as easily could have placed the Members, Announcements, or any other custom web parts on the page. Initial configuration data for these web parts is usually passed through a child CData element. In our case, we specify the web part, its frame type, title, and an initial image. Keep in mind that the user could drastically modify these initial settings in the future.

The WebPartZoneID and WebPartOrder attributes are valid in both AllUsersWebPart and View elements. These attributes control the placement of the web parts. The WebPartZoneID places the web part in a named zone, and the WebPartOrder specifies the order of the web part within a zone. In our example detailed in Listing 2.24, DEFAULT.ASPX has two zones definedLeft and Right.

Listing 2.24. DEFAULT.ASPX Web Part Zone Declarations

[View full width]

 <tr>   <!-- Middle column -->   <td valign="top" width="70%">     <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly"  Title="loc :Left" />     &nbsp;   </td>   <td>&nbsp;</td>   <!-- Right column -->   <td valign="top" width="30%">     <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly"   Title="loc:Right" />     &nbsp;   </td>   <td>&nbsp;</td> <tr> 

The View element is very similar to the AllUsersWebPart. Instead of a named web part, the View element displays the contents of a list or library. This makes a lot of sense if you recall how web parts are added to a page through the GUI. As shown in Figure 2.22, the web part list that you select from includes not only web parts but also the lists and libraries of a site. In Figure 2.22, these lists include Announcements, Contacts, Events, General Discussion, and Links. Actually, these lists use the same web part class but with different connections to the underlying data source. The Announcements web part connects to the Announcements list, the Contacts web part connects to the Contacts list, and so on. This is exactly the same metaphor that the AllUsersWebPart and View elements use.

Figure 2.22. Web Part List showcasing views of lists.


In Listing 2.23, the View elements reference a List attribute and a BaseViewID attribute of 0. The List attributes reference 104 and 106. These List values were defined in the Configuration section of ONET.XML and correspond to Announcements and Events, respectively. Thus, a view of Announcements and Events will be added to the DEFAULT.ASPX page. The BaseViewID is the initial view selected for the web part. Those view IDs are initially defined within SCHEMA.XML. Figure 2.23 shows the initial views for an event list that originated from SCHEMA.XML. Through BaseViewID, the initial view of the Events list could be set to All Events, Calendar, or Current Events. Of course, this could always be changed through the GUI after the site has been created.

Figure 2.23. Example Event List views.


Only a subset of View element attributes is used within ONET.XML. SCHEMA.XML, which we describe later, more fully utilizes the View attributes. Table 2.12 describes all the View element attributes.

Table 2.12. <View> Attributes

Attribute

Required

Type

Description

AggregateView

No

Boolean

If trUE, indicates that the view is a merge forms view. This pertains to an XML Form library.

BaseViewID

No

Boolean

Specifies the view to use when referenced from ONET.XML. When used in SCHEMA.XML, defines an identifier for the view.

DefaultView

No

Text

If trUE, indicates that this is the default view.

DisplayName

No

Boolean

This is the name of the view as shown in the Quick Launch view.

Editor

No

Text

Specifies the editing tool used to create the view. Valid choices are SharePoint Team Services, FrontPage, and Custom.

FailIfEmpty

No

Boolean

If trUE, a view that returns no items will return an HTTP error code. If FALSE, <ViewEmpty><![CDATA[<I> There are no items in this view.</I>]]></ViewEmpty> will be returned. This only applies if you are interacting with the view through the SharePoint API. There will be no noticeable difference when looking at the view through the AllItems.aspx or similar page.

FileDialog

No

Boolean

If TRUE, the view is marked as the one to be displayed from the Microsoft Office application suite.

   

One can test its results through the URL http://MyWSSServer/Subweb1/_vti_bin/owssvr.dll?location=MyDocLibraryName&dialogview=FileSave.

FPModified

No

Boolean

If TRUE, the view has been modified by FrontPage and therefore can no longer be customized by the SharePoint web user interface.

FreeForm

No

Boolean

If trUE, more flexibility is allowed for formatting the various fields of a list.

Hidden

No

Boolean

If trUE, the view is not displayed through the SharePoint web user interface. For example, the Microsoft Office views discussed in the FileDialog attribute are hidden.

List

No

Integer

Specifies the list type defined within ONET.XML.

Name

No

Text

Specifies a unique name for the view. However, the value of the DisplayName attribute is what is exposed to users.

OrderedView

No

Boolean

If trUE, specifies that the view is ordered.

Path

No

Text

Specifies the filename for the view. This is primarily used with FileDialog views and is in lieu of specifying this file with the Url attribute.

ReadOnly

No

Boolean

If trUE, the view cannot be modified. This is helpful if you never want users modifying the view through the web user interface.

RecurrenceRowset

No

Boolean

If trUE, recurring events will be expanded in the view. This is only applicable to the events list.

RowLimit

No

Integer

Specifies the maximum number of items to show per page. Valid values include an integer or None. If None is specified, all records are returned with no paging.

Scope

No

Text

This only applies to libraries. Valid values include FilesOnly, Recursive, and RecursiveAll. If FilesOnly, display the files of the current folder. If Recursive, display all files so that they appear at the root level. If RecursiveAll, show all files and subfolders so that they appear at the root level. If left unspecified (the default), the files and subfolders of the current folder will be displayed.

Threaded

No

Boolean

If TRUE, items will be threaded. The best example of this is within the discussion board list.

Type

No

Text

Specifies the view rendering. Valid choices include HTML, Chart, and Pivot.

Url

No

Url

Binds a URL of the list or library view file to a view. This is akin to the Path attribute.

WebPartOrder

No

Integer

The order in which the view web part will be placed within an already specified zone.

WebPartZoneID

No

Text

The zone in which the view web part will be placed.





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