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


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=, Culture=neutral, PublicKeyToken=be322df48bc9f56c" Namespace="customupload" %>


 <SharePoint:RenderingTemplate ID="CustomDocumentLibraryViewToolBar" runat="server">
  <wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="<img src='/_layouts/images/blank.gif' alt=''>" RightButtonSeparator="&nbsp;&nbsp;" runat="server">
    <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"/>
      <SharePoint:PagingButton ID="PagingButton1" runat="server"/>
      <SharePoint:ListViewSelector ID="ListViewSelector1" runat="server"/>


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



Comments (8)
  1. HiteshDalal says:

    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

  2. manasa28 says:

    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.

  3. manasa28 says:

    I implemented as mentioned above and created a custom library but it throws be below error can anyone please guide me further.

    Server Error in ‘/’ Application.


    Value does not fall within the expected range.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException: Value does not fall within the expected range.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

    Stack Trace:

    [ArgumentException: Value does not fall within the expected range.]

      Microsoft.SharePoint.SPFieldCollection.GetField(String strName, Boolean bThrowException) +471

      Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException) +120

      Microsoft.SharePoint.SPListItem.GetValue(String strName) +54

      Microsoft.SharePoint.SPListItem.get_Item(String fieldName) +51

      customupload.MyUploadMenu.SetMenuItemProperties() +1737

      Microsoft.SharePoint.WebControls.ToolBarMenuButton.OnLoad(EventArgs e) +124

      System.Web.UI.Control.LoadRecursive() +66

      System.Web.UI.Control.LoadRecursive() +191

      System.Web.UI.Control.LoadRecursive() +191

      System.Web.UI.Control.LoadRecursive() +191

      System.Web.UI.Control.LoadRecursive() +191

      System.Web.UI.Control.AddedControl(Control control, Int32 index) +350

      Microsoft.SharePoint.WebPartPages.ListViewWebPart.CreateChildControls() +4371

      System.Web.UI.Control.EnsureChildControls() +146

      System.Web.UI.Control.PreRenderRecursiveInternal() +61

      System.Web.UI.Control.PreRenderRecursiveInternal() +224

      System.Web.UI.Control.PreRenderRecursiveInternal() +224

      System.Web.UI.Control.PreRenderRecursiveInternal() +224

      System.Web.UI.Control.PreRenderRecursiveInternal() +224

      System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394


    Version Information: Microsoft .NET Framework Version:2.0.50727.4016; ASP.NET Version:2.0.50727.4016

  4. says:

    Create a list with name: Test2

    Add a new column with name: CustomId has type "Single line of text"

  5. David says:

    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.

  6. Rubén says:

    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?

  7. Rubén says:

    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?

Comments are closed.

Skip to main content