Custom upload page in Layouts for document library and it's Navigation from upload menu in the Toolbar. Bend it !! Custom upload menu for the document library.

You just dont want to use the OOB upload.aspx in the "Layouts" to upload the documents in to the document library and you have created your custom upload.aspx (with all your requirements) based on the look and feel of OOB upload.aspx. Now your custom upload.aspx page is available in the "Layouts", But................................................. You started wondering that how to integrate the Navigation to the New custom upload.aspx page from the "Upload Menu" in the document library toolbar. You might have created the customupload.aspx and placed in the "Layouts" but clicking on the upload single or multiple document in the Upload menu will navigate you to "Upload.aspx" and not to the "Customupload.aspx"...

Thinking again............ Oh got it !!! Yes, I can add a new menu item through "customaction" feature and can navigate to the "CustomUpload.aspx" page to upload the documents. Think again ...... Yes, You can do it !! But what about the existing OOB menu item which navigates you to the OOB "upload.aspx" page. Still thinking ........ Hurray !!! Through "HideCustomAction" i will hide the existing OOB menu item in the upload menu which navigates to the OOB upload.aspx page.

Let me interrupt here !! As long the "CustomAction" feature is considered, you can add a new item under the "UploadMenu". But hiding the existing OOB menu item is not possible through the "HideCustomAction" feature. The "HideCustomAction" feature can hide the item which has been rendered through the CustomAction feature framework such as Site Action, Site Setting.... etc. Even you cannot hide the item from the "ECB" menu through HideCustomAction but can add a new menu item in the ECB menu through custom action. Because the ECB menu is rendered by the JavaScript from Core.js file. Likewise the "Upload menu" is rendered through a class library as a web control from the Microsoft.SharePoint.dll

So "HideCustomAction" feature can be used only to hide the item which are rendered through the custom action feature.

Following are some truth about the document library (as well "Lists") toolbar and the way to render the custom control in the toolbar :

1. The toolbar of the document library consists of New Menu, Upload menu, Actions Menu and Settings Menu. These menus are rendered by the sharepoint dll and not by any JavaScript.

2. To customize the Upload Menu, Create a class which inherits from the Microsoft.Sharepoint.WebControls.UploadMenu class and Override the “SetmenuItemProperties” method to navigate to the custom upload page. In this method it has been hard coded to navigate to the OOB upload.aspx.

 

3. The code snippet and the sample project has been attached in this post.

 

4. Compile the class library and place the DLL in the GAC.

 

5. The Rending Template for the document library is in the defaulttemplates.ascx control under 12/Template/Control template. The rendering template ID is “DocumentLibraryViewToolbar”. This template renders the New menu, Upload menu, Actions menu and Settings menu in the toolbar. The template looks like follows :

<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"/>

</Template_RightButtons>
</wssuc:ToolBar>
</Template>
</SharePoint:RenderingTemplate>

6. Modifying the OOB files are not supported so copy the defaulttemplates.ascx and save it with a custom name under 12/Template/Control Template.

7. Modify the “DocumentLibraryViewToolbar” in the custom ascx such that to render your custom upload menu from the class library you created. (Note : You need to add your assembly reference and register the tag prefix in the Custom ascx control. The sample customdefaulttemplates.ascx control is attached in this post)

8. The following are the snippet from the custom ascx control :

Along with the other existing tag prefixes need to add the tag prefix for your custom upload menu control dll

<% @Register TagPrefix="MyUpload" Assembly ="customupload, Version=1.0.0.0, Culture=neutral, PublicKeyToken=be322df48bc9f56c" Namespace="customupload" %>

<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 ID="NewMenu1" AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>
<MyUpload:MyUploadMenu ID="UploadMenu1" AccessKey="<%$Resources:wss,tb_UploadMenu_AK%>" runat="server"/>
<SharePoint:ActionsMenu ID="ActionsMenu1" AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server"/>
<SharePoint:SettingsMenu ID="SettingsMenu1" AccessKey="<%$Resources:wss,tb_SettingsMenu_AK%>" runat="server"/>
</Template_Buttons>
<Template_RightButtons>
<SharePoint:PagingButton ID="PagingButton1" runat="server"/>
<SharePoint:ListViewSelector ID="ListViewSelector1" runat="server"/>
</Template_RightButtons>
</wssuc:ToolBar>
</Template>
</SharePoint:RenderingTemplate>

9. Next step is to render the custom rendering template to the document library so that the custom upload menu will be rendered in the toolbar. For this the "ToolbarTemplate" property of the View should be changed in the schema.xml file of teh document library definition. As modifying the OOB files are not supported, Copy the “DocumentLibrary” folder from 12/Template/Features and paste in the same place as “CustomDocumentLibrary”.

10. Change the feature ID of the “CustomDocumentLibrary”

11. Open the schema.xml file of custom document library and add the “ToolbarTemplate=CustomDocumentLibraryViewToolbar” attribute to the “View BaseID=1”. The sample custom document library definition with schema.xml changes is attached in this post.

12. Install the feature and activate it.

13. Create a document library using the custom document library definition and you can test that the custom upload menu has been added to the document library toolbar.

14. Now clicking on the upload document will navigate you to the custom upload.aspx page

HAPPY CUSTOMIZING

 

CustomUpload.zip

Comments

  • Anonymous
    July 18, 2008
    PingBack from http://blog.a-foton.ru/2008/07/custom-upload-page-in-layouts-for-document-library-and-its-navigation-from-upload-menu-in-the-toolbar-bend-it-custom-upload-menu-for-the-document-library/

  • Anonymous
    December 31, 2009
    Great code. Very much useful. Tried to use this technique. However while performing above steps, the toolbar is not getting displayed and hence does not fulfil all objective. Can you guide which steps are critical for resolving. We verified : (a) copy the defaulttemplates.ascx to a new name (b) modifying “DocumentLibraryViewToolbar” in the custom ascx

  • Anonymous
    February 15, 2010
    I have done exactly what you have told.I installed and activated the feature but still the customised upload menu doesn't apper and it shows the same old upload page and redirects to the same old upload.aspx. Can anyone please help why is it not working.

  • Anonymous
    February 23, 2010
    The comment has been removed

  • Anonymous
    January 04, 2011
    The comment has been removed

  • Anonymous
    September 01, 2011
    What about setting the SPWeb.CustomUploadPage Property! Gets or sets the path to a custom application page for uploading files. This should keep all the UI in order.

  • Anonymous
    September 14, 2011
    Hello, i tried this and completed all the steps above but i when i hit create library i dont see the Custom Create Library Option, just see Document library, Form Library etc. Do anyone know why? Or a way  i can get some help?

  • Anonymous
    September 14, 2011
    Hello, i tried this and completed all the steps above but i when i hit create library i dont see the Custom Create Library Option, just see Document library, Form Library etc. Do anyone know why? Or a way  i can get some help?