Removing Attachment button from MOSS Form Toolbar

I have a requirement where I need to remove the Attachment button from the Sharepoint Form Toolbar that comes with OOTB NewForm.aspx and EditForm.aspxSharePoint tool bar Attachment

you can remove the attachment support from your list by setting DisableAttachments=”TRUE” in the <List in the Schema file. But My requirement was to keep the attachment support so the attachment can only be added from different place and not from the edit or new form pages.

To do this, you will need to override the .ascx based toolbar templates by using a custom template that overrides the OOTB toolbar.

If you look at DefaultTemplates.ascx under C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES it has a RenderTemplate with an ID of “ListForm” and the RenderingTemplate contains <SharePoint:FormToolBar runat=”server”/> . FormToolBar has a TemplateName property which can be used to override the default rendering template for the toolbar.

Copy the “ListForm” rendering template to your own ascx (myCustomTemplates.ascx) file and also add following custom template to the ascx file

<br /> <SharePoint:RenderingTemplate ID="NoAttachMentFormToolBar" runat="server"><br /> <Template></p> <table class="ms-toolbar" id="toolBarTbl" cellSpacing="0" cellPadding="2" width="100%" border="0"> <tr> <td class="ms-toolbar" noWrap width="99%"><br />                     <img height="18" alt="" src="/_layouts/images/blank.gif" width="1" /></td> <td class="ms-toolbar" noWrap><br />                     <span class="ms-descriptiontext" id="reqdFldTxt" style="PADDING-RIGHT: 3px; WHITE-SPACE: nowrap"><br />                     <span class="ms-formvalidation">*</span> indicates a required field</span></td> </tr> </table> <p></Template><br /> </SharePoint:RenderingTemplate><br /> 

Now change the ID of ListForm rendering template that you copied into your ascx to MyCustomFormTemplate and add TemplateName=”NoAttachMentFormToolBar” to the <SharePoint:FormToolBar… control.

<br /> <SharePoint:RenderingTemplate ID="MyCustomFormTemplate" runat="server"><br /> 	<Template><br /> 		<SPAN id='part1'><br /> 			<SharePoint:InformationBar runat="server"/><br /> 			<wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbltop" RightButtonSeparator="&nbsp;" runat="server"><br /> 					<Template_RightButtons><br /> 						<SharePoint:NextPageButton runat="server"/><br /> 						<SharePoint:SaveButton runat="server"/><br /> 						<SharePoint:GoBackButton runat="server"/><br /> 					</Template_RightButtons><br /> 			</wssuc:ToolBar><br /> 			<SharePoint:FormToolBar runat="server" TemplateName="NoAttachMentFormToolBar"/><br /> 			<TABLE class="ms-formtable" style="margin-top: 8px;" border=0 cellpadding=0 cellspacing=0 width=100%><br /> 			<SharePoint:ChangeContentType runat="server"/><br /> 			<SharePoint:FolderFormFields runat="server"/><br /> 			<SharePoint:ListFieldIterator runat="server"/><br /> 			<SharePoint:ApprovalStatus runat="server"/><br /> 			<SharePoint:FormComponent TemplateName="AttachmentRows" runat="server"/><br /> 			</TABLE></p> <table cellpadding=0 cellspacing=0 width=100%> <tr> <td class="ms-formline"><IMG SRC="/_layouts/images/blank.gif" width="1" height="1" alt=""></td> </tr> </table> <p><TABLE cellpadding=0 cellspacing=0 width=100% style="padding-top: 7px"></p> <tr> <td width=100%><br /> 			<SharePoint:ItemHiddenVersion runat="server"/><br /> 			<SharePoint:ParentInformationField runat="server"/><br /> 			<SharePoint:InitContentType runat="server"/><br /> 			<wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbl" RightButtonSeparator="&nbsp;" runat="server"><br /> 					<Template_Buttons><br /> 						<SharePoint:CreatedModifiedInfo runat="server"/><br /> 					</Template_Buttons><br /> 					<Template_RightButtons><br /> 						<SharePoint:SaveButton runat="server"/><br /> 						<SharePoint:GoBackButton runat="server"/><br /> 					</Template_RightButtons><br /> 			</wssuc:ToolBar></td> </tr> <p></TABLE><br /> 		</SPAN><br /> 		<SharePoint:AttachmentUpload runat="server"/><br /> 	</Template><br /> </SharePoint:RenderingTemplate></p> <p>

That’s it. Copy your myCustomTemplates.ascx into C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES. Now Sharepoint will use the NoAttachMentFormToolBar template when rendering the custom template.

one last thing, you will need to point the editform and newform pages to your new custom template. In your list schema.xml file modify the <Form element to point to the new template

Don’t forget IISRESET after copying the new schema and custom ascx control tempalte to 12 hive

<br />  <Forms><br />       <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" /><br />       <Form Type="EditForm" Url="EditForm.aspx" WebPartZoneID="Main" Template="MyCustomFormTemplate" /><br />       <Form Type="NewForm" Url="NewForm.aspx" WebPartZoneID="Main" Template="MyCustomFormTemplate"/><br />     </Forms></p> <p>

Remove Attachment button from Sharepoint form toolbar


Satesh attempt to post a code block into comments for some reason is not working, so here is the code bloc, Thanks for the comment:

<br />  <SharePoint:RenderingTemplate ID="NoAttachMentFormToolBar" runat="server"><br />  <Template><br />   <wssuc:ToolBar CssClass="ms-toolbar" id="toolBarTbl" RightButtonSeparator="&nbsp;" runat="server"><br />   </wssuc:ToolBar><br />  </Template><br /> </SharePoint:RenderingTemplate></p> <p>


20 thoughts on “Removing Attachment button from MOSS Form Toolbar

  1. Thank your for your post. I have just a question:

    How do I find out, which schema.xml file is the right one for my list. I want to create a new custom template of an event list.
    I have modified the the schema.xml file under ..\web server extensions\12\TEMPLATE\FEATURES\EventList\Events but it doesn’t work 😦

    Thank you

  2. Hi JD,
    first of all, you should never edit original files under the “12 hive”. Instead, create a new feature where you define your custom list. For the actual question: it doesn’t work probably for the reason that the OOTB Events list has content types enabled and in that case it ignores the Template property as it’s defined in the content type itself.
    Here’s a brief set you could do:
    1. Make the list ready through browser
    2. pull it out with Solution Generator (if you don’t have ite, it’s in Windows SharePoint Services 3.0 Tools, VSeWSSv11.exe from Microsoft’s site)
    3. by this time you probably have created your custom template, modify the pulled out schema.xml accordingly (set the Template property to poin to your template)
    4. create a feature out of it
    5. install & activate the feature
    6. create you custom list from the site
    7. Done 🙂

    Hope this helps,
    – Sam

    • I did the same way you told above ..I copied my ascx file in
      \web server extensions\12\TEMPLATE\controltemplates.
      I have custom list fopr Contacts.In that list I have schema.xml file.custom contenttype is attached to this customlist.I updated the Forms Tag in schema.xml file to use my custom template like this

      Form Type=”EditForm” Url=”EditForm.aspx” Template=”MyCustomFormTemplate” WebPartZoneID=”Main”

      Form Type=”NewForm” Url=”NewForm.aspx” Template=”MyCustomFormTemplate” WebPartZoneID=”Main”

  3. Hi Ketul,

    I am trying to remove New from DocumentViewtoolbar of my Document Library, but after changing ID of Rendertemplate it is not working for that particular DL.

    I added UserControl to my customize page also, but it doesn’t seems useful

  4. Thanks for Quick Response, but i am trying to remove New from Document Library I created. The Solution you provided remove New from Every Document Library created within site collection. Revert me soon it’s urgent. Thanks in Advance

  5. Yes that’s the problem with the solution on MSDN Blog. It might be a long shot but if you have a customized the schema for document library than <View DefaultView=”TRUE”……. will have <Toolbar Type=”Standard”…. you can try to use the Freeform toolbar <Toolbar Type=”Freefrom”…. and remove the new button from HTML

  6. Hi Ketul, thanks for an excellent post, it got me on the right track. I would just like to suggest a small change to your solution and this essentailly removes the ‘attachment’ link however, it will continue to include any custom actions defined for the toolbar and also the ‘RequiredField’ message will continue to display.

  7. Hi Ketul’s!

    Great post!

    I have a different scenario.
    Suppose you want to keep the attach file option, but on the attachment list, disable the remove option?

    In this case where in the DefaultTemplates.ascx should be modified?

    Thanks in advance for your attention! (^_^)

  8. If you want to remove the list toolbar completely from your site, you can use CSS….



  9. I tried to hide the Attachment link,using the code what you mentioned above.I updated my custom list schema also to use the custom list.

    restarted iis

    but I am unable to hide the attach File link on the tool bar.
    Could you please suggest me where I am doing wrong.

    My list is custom list.I updated that schema file to use the custom template.

  10. I posted to your bbs from Japan.
    I am japanese.
    I have just a question:

    I want to remove the workflow of toolbar in DispForm.ascx.
    But I cannot remove it.
    I used sharepoint 2007

    Help me.

  11. The OOTB Meeting Agenda newform.aspx and editform.aspx have an attachment button on the toolbar, but the toolbar lacks a check spelling button like the toolbar used on the newform for Announcement list items. How would you add the spelling button to the toolbar for Agenda items?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s