none
Hide Upload Document item in Ribbon

    問題

  • I created a document library set to use a "Document Set" content type.  I am hiding the "Document" content type, so that when a user clicks "New Document", in the Ribbon, they are only able to create a Document Set.  Is there a way to hide "Upload Document" item in them Ribbon at this level?  Meaning, once the Document Set is created the user should be allowed to "upload" documents into the Document Set?  I want to prevent them from uploading documents at the document set creation level.
    2012年6月14日 下午 05:06

解答

  • You can also hide the items in the Ribbon with CSS:

    <style type="text/css">
    #Ribbon\.Documents\.New 
    {
    display: none !important;
    }
    </style>


    /blog twttr @esjord

    • 已標示為解答 obautista 2012年6月15日 下午 05:11
    2012年6月15日 下午 03:10

所有回覆

  • OR best way try this ... Let me know if this helps..

    Best way is you can disable the option within the document library.
    
    1. Edit the document library page and Add a content editor webpart in your document library
    
    2. Paste below script in source code of CEWP
    
    <script type="text/javascript">
    function GetElementByText(tagName, title)
    {
    var a = document.getElementsByTagName(tagName);
    
    for (var i=0; i < a.length; i++)
    {
    if (a[i].text)
    {
    if (a[i].text === title)
    {
    return a[i];
    }
    }
    }
    
    return null;
    }
    
    if (window.onload)
    {
    var oLoad = window.onload;
    window.onload = function bodyLoad()
    {
    oLoad();
    
    var o = GetElementByText("ie:menuitem","Upload Document");
    var k = GetElementByText("ie:menuitem","Upload Multiple Documents");
    if (o || k)
    {
    o.disabled = true;
    k.disabled = true;
    }
    }
    }
    </script>

    2012年6月14日 下午 05:59
  • Thanks - but this hides the Library Tools tab, so I am not able to get to the Documents or Library sections in the Ribbon.
    2012年6月15日 下午 02:00
  • Hi,

    You can use TrimById funcion by Object model.

    I suggest you create a webpart and overrides OnPreRender by putting this code:

    ...
    Dim ribbon As Microsoft.SharePoint.WebControls.SPRibbon = SPRibbon.GetCurrent(Me.Page)
    
    ribbon.TrimById("Ribbon.Documents.New.AddDocument")
    ...

    All controls ids: http://msdn.microsoft.com/en-us/library/ee537543(en-us,office.14).aspx

    Remember that you MUST paste this code at OnPreRender not in CreateChildControls method.

    Regards!



    José Quinto Zamora
    SharePoint and Search Specialist at SolidQ(http://www.solidq.com)
    MCITP and MCPD in SharePoint 2010
    http://blogs.solidq.com/sharepoint

    2012年6月15日 下午 02:19
  • TrimById must be used in a Farm Solution, correct?  Unfortunately, this is SharePoint Online and must be a Sandboxed Solution.  Additionally, I need the Upload Document button to be disabled or hidden only when creating Document Sets in the doc library.  Within the Document Set - I do want the user to be able to upload documents.  Given this requirement is jquery/css route my only option?
    2012年6月15日 下午 02:42
  • Hi,

    You could try to create a webpart with this code in a sandbox solution.

    Maybe you need to put this webpart only in pages that you are interested in.

    You can see limitations on sandbox: http://msdn.microsoft.com/en-us/library/gg615454.aspx#BKMK_BlockClasses

    And What Can Be Implemented in SandBox: http://msdn.microsoft.com/en-us/library/gg615464.aspx

    Regards!



    José Quinto Zamora
    SharePoint and Search Specialist at SolidQ(http://www.solidq.com)
    MCITP and MCPD in SharePoint 2010
    http://blogs.solidq.com/sharepoint

    2012年6月15日 下午 02:57
  • You can also hide the items in the Ribbon with CSS:

    <style type="text/css">
    #Ribbon\.Documents\.New 
    {
    display: none !important;
    }
    </style>


    /blog twttr @esjord

    • 已標示為解答 obautista 2012年6月15日 下午 05:11
    2012年6月15日 下午 03:10
  • Hi,

    You can create a sandbox solution with the following feature\elements.xml to remove Upload document in the Ribbon. If you need this active for only one library you can either create a new Content type from document and then specify the Id in RegistrationId or you will have to create a new list template for you document library and specify the id of list template in RegistrationId.

    <CustomAction
        Id="RemoveExplorerButton"
        Location="CommandUI.Ribbon"
        RegistrationType="List"
        RegistrationId="{contentTypeId}">
        <CommandUIExtension>
          <CommandUIDefinitions>
            <CommandUIDefinition
              Location="Ribbon.Library.Documents.upload" />  -> verify this
          </CommandUIDefinitions>
        </CommandUIExtension>
      </CustomAction>

    2012年6月15日 下午 03:34
  • This did the trick.  It hid the Upload button and am hiding the Add New with the Main web part zone:

    <style type="text/css"> 
    #Ribbon\.Documents\.New\.AddDocument-Large
    {     
    	display:none !important; 
    } 
    </style>
    <style type="text/css"> 
    td.ms-addnew
    {     
    	display:none !important; 
    } 
    </style>

    2012年6月15日 下午 05:10
  • I had the same issue as you and this worked for me.  Thank you. 

    C# Developer

    2014年1月28日 下午 09:05