Customizing the List Toolbar Template - WSS 3.0 & MOSS

SharePoint Rendering Templates

All the rendering Templates for the List are defined in the defaulttemplates.ascx in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES folder.

This defaulttemplates.ascx control defines the toolbar controls and the form controls for every list template.

The following table explains the rendering template Id and the respective List templates it associated with. Few examples of rendering template have been taken in this table:

                   Rendering Template

                   List Template

ViewToolbar

Custom List, Tasks List,

DocumentLibraryViewToolBar

Document Library

WikiLibraryViewToolBar

Wiki Library

WebPartGalleryViewToolBar

Web Part Gallery List

PictureLibraryViewToolBar

Picture Library List

SiteListGalleryViewToolBar

Site List Gallery

These rendering templates have been associated with the List template through the schema.xml file of the list definition.

All the OOB SharePoint List definitions are created as a feature. Each definition has a schema.xml file which defines the Fields and Views of the list. In the Views you can set the “ToolbarTemplate” property to select the template from the defaulttemplates.ascx.

In this blog will walk through you on customizing the toolbar of the document library.

Customizing the toolbar of the document library template

So far it’s clear that the rendering template in the defaulttemplates.ascx renders the controls for the toolbar for every list in the SharePoint. For document library the rendering template is “DocumnetLibraryViewToolbar”. Following is the snippet of “DocumentLibraryViewToolbar” from the defaulttemplates.ascx.

<SharePoint:RenderingTemplate ID="DocumentLibraryViewToolBar" runat="server">

      <Template>

            <wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="<img src='/_layouts/images/blank.gif' alt=''>" RightButtonSeparator="&nbsp;&nbsp;" runat="server">

                  <Template_Buttons>

                        <SharePoint:NewMenu AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>

                        <SharePoint:UploadMenu AccessKey="<%$Resources:wss,tb_UploadMenu_AK%>" runat="server"/>

                        <SharePoint:ActionsMenu AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server"/>

                        <SharePoint:SettingsMenu AccessKey="<%$Resources:wss,tb_SettingsMenu_AK%>" runat="server"/>

                  </Template_Buttons>

                  <Template_RightButtons>

                        <SharePoint:PagingButton runat="server"/>

                        <SharePoint:ListViewSelector runat="server"/>

                  </Template_RightButtons>

            </wssuc:ToolBar>

      </Template>

</SharePoint:RenderingTemplate>

The gray shaded part in the above code shows the SharePoint controls rendered for the toolbar through this template. The New, Upload, Action and Settings are the menu control rendered in the left part of the toolbar. The ListViewSelector is the view selector control rendered in the right of the toolbar.

If you want to customize this toolbar then you need to create your custom rendering template in the defaulttemplates.ascx control. Consider you want to customize toolbar in such a way that you want to restrict the user from uploading document and just want them to create the document from the SharePoint server. To achieve this you need to create a rendering template without upload menu in the defaulttemplates.ascx and need to associate this template with the schema.xml of the list definition by setting the “ToolbarTemplate” view property.

Modifying the OOB files are not supported so you need to create a customdefaulttemplates.ascx to add the rendering template without upload menu and you need to create a custom document library definition to associate the toolbar template with the definition.

Following are the steps to customize the toolbar template in the supported way.

      

1. Copy the defaulttemplates.ascx and place it in the same location C:\Program Files\Common Files\Microsoft Shared\webserverextensions\12\TEMPLATE\CONTROLTEMPLATES. You can give any custom name to the ascx file.

2. Remove all the rendering templates from the custom defaulttemplates.ascx except the “DocumentLibraryViewToolbar”. Change the ID to any custom name say “CustomDocumentLibraryViewToolbar”.

3. Remove the “SharePoint: UploadMenu” control rendering from the template and save the custom defaulttemplates.ascx. The resultant rendering template looks like follows:

<SharePoint:RenderingTemplate ID="CustomDocumentLibraryViewToolBar" runat="server">

      <Template>

            <wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="<img src='/_layouts/images/blank.gif' alt=''>" RightButtonSeparator="&nbsp;&nbsp;" runat="server">

                  <Template_Buttons>

                        <SharePoint:NewMenu AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/> <SharePoint:ActionsMenu AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server"/>

                        <SharePoint:SettingsMenu AccessKey="<%$Resources:wss,tb_SettingsMenu_AK%>" runat="server"/>

                  </Template_Buttons>

                  <Template_RightButtons>

                        <SharePoint:PagingButton runat="server"/>

                        <SharePoint:ListViewSelector runat="server"/>

                  </Template_RightButtons>

            </wssuc:ToolBar>

      </Template>

</SharePoint:RenderingTemplate>

4. Create a custom document library definition. To create a custom document library definition copy the “DocumentLibrary” folder from C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES and paste in the same location with a custom name.

 

5. Change the feature Id of the custom document library definition in the feature.xml file. Change the Title, Description and other property you want to modify.

 

6. Open the schema.xml file of your custom document library definition and in the default view (BaseViewId=1) add the “ToolbarTemplate” attribute which mentions your custom rendering template created without the upload menu. The code snippet looks like follows :

<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" ToolbarTemplate="CustomDocumentLibraryViewToolBar" DisplayName="$Resources:core,All_Documents;" DefaultView="TRUE" MobileView="True" MobileDefaultView="True" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/dlicon.png" Url="Forms/AllItems.aspx"><!-- _locID@DisplayName="camlidDc1" _locComment=" " -->

 

7. Save the schema.xml file. Do an IISRESET. Install and activate the custom document library definition feature through stsadm command.

 

8. Now the custom document library definition will be available in the gallery while you create a dcumnet library. Select the custom document library and create the document library in the sharepoint site.

 

9. Now you can notice that the document library toolbar doesn’t have the “Upload Menu” in it.

Further, If you want to override any of the functionality of this control. Then you can create a class library inheriting this control and ovverride the property you are looking for. Then add your DLL reference in the custom defaulttemplates.ascx and render the custom control instead of the OOB controls in the toolbar rendering template.

                             HAPPY CUSTOMIZING.