Friday, February 8, 2008

How to hide Upload Toolbar button from a Forms Library?

Last month, I came across a requirement where I need to hide Upload toolbar button on one of our forms library. I tried to find on net, and got some clues how to do this. Adding a custom control under c:\Program Files\Common Files\Microsoft shared\Web service extensions\12\Template\CONTROLTEMPLATES, this can be done.

Reference: http://blogs.msdn.com/dipper/archive/2006/10/05/How-to-Remove-or-hiding-items-in-List-toolbar-in-Sharepoint-Server-2007.aspx

But using this way, It hides toolbar buttons for all of the document library and Forms library. Following is the workaround to hide toolbar buttons on specific forms library.

Step 1: Design a InfoPath Form with some controls on it.

Step 2: Publish InfoPath form as a Site Content Type “MyCustomContentType” on Forms Template Library

Step 3: Using Visual Studio Sharepoint tools, Create custom list definition for Forms Library. Tool used is Visual Studio 2005 extensions for Windows SharePoint Services 3.0, Version 1.0) Tools for developing custom SharePoint applications.

Step 4: Under Schema.Xml add attribute ToolbarTemplate=”myToolBarID” to <View BaseViewID="1" > element as follows

<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,All_Tasks;" DefaultView="TRUE" MobileView="True" MobileDefaultView="False" ToolbarTemplate="myToolBarID” SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/issues.png" Url="AllItems.aspx>

Step 5: Build the custom form library definition and deploy it/

Step 6: Create a forms library based on this newly created definition.

Step 7: Toolbar for the newly created forms library will be missing.

Step 8: Save following code snippet as MyCustomFormLibToolBar.ascx into c:\Program Files\Common Files\Microsoft Shared\Web Service Extensions\12\Templates\CONTROLTEMPLATES

<%@ Control Language="C#" AutoEventWireup="false" %>

<%@Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%>

<%@Register TagPrefix="SPHttpUtility" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.Utilities"%>

<%@ Register TagPrefix="wssuc" TagName="ToolBar" src="~/_controltemplates/ToolBar.ascx" %>

<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="~/_controltemplates/ToolBarButton.ascx" %>

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

<Template>

<wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="''" RightButtonSeparator=" " 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>


Step 9: IISReset

Step 10: Toolbar for the newly created Forms library is available.

Step 11: Open Advance Settings for the Forms Library settings

Step 12: Check Allow multiple content types, Open as Web Page.

Step 13: Select Add existing content type, and add “MyCustomContentType”.

The similar ascx control can be used to hide or remove toolbar buttons on specific SharePoint List, Document Library as well.