Compartilhar via


How to: Customize the Document Set Ribbon in SharePoint Server 2010 (ECM)

Applies to: SharePoint Server 2010

The document sets feature includes its own ribbon tab. This topic explains how to add a button to the document set ribbon. By adding a button to the ribbon, you set up a scenario where you can implement functionality that uses the ribbon to perform specific actions.

Use two XML files to create the ribbon button. Place these files in the Features folder (which is, by default, located in the Program Files\common files\Microsoft shared\web server extensions\14\template\features folder), in their own folder. Name this folder addzipribbon. The two files, Element.xml and Feature.xml, define the elements of the ribbon customization and the feature registration, respectively.

Users might want to download all of a document set’s contents rather than download each file individually. Document sets use an export framework for sending document sets to content organizers by using Send To, but you can also use the export framework to export .zip files so that users can download them. Do this by creating a .dll file that uses the document sets object model.

Create and Add a Button

  • Create the Element.xml file.

    Element.xml

    <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
      <CustomAction
        Id="Ribbon.Documents.DocsetZip"
        Title="Download Document Set as ZIP"
        RegistrationType="ContentType"
        RegistrationId="0x0120D520" 
        Location="CommandUI.Ribbon"
        >
        <CommandUIExtension>
          <CommandUIDefinitions>
            <CommandUIDefinition
              Location="Ribbon.ManageDocumentSet.MDS.Manage.Controls._children"> 
      <Button
    Id="Ribbon.ManageDocumentSet.MDS.Manage.Controls.DownasZip"
                        Sequence="20"
                        Command="Ribbon.ManageDocumentSet.MDS.Manage.DownZip"
                        Alt="Download as ZIP"
                        Image16by16="/_layouts/images/zipfile16x.png"
                        Image32by32="/_layouts/images/zipfile32x.png"
                        LabelText="Download as ZIP file"
        ToolTipTitle="Download as ZIP file"
        ToolTipDescription="Compress the document set and download"
        TemplateAlias="o1"
    />
            </CommandUIDefinition>
          </CommandUIDefinitions>
          <CommandUIHandlers>
            <CommandUIHandler
              Command="Ribbon.ManageDocumentSet.MDS.Manage.DownZip"
              CommandAction="javascript:__doPostBack('DownloadZipDelegateEvent', '')" />
          </CommandUIHandlers>
        </CommandUIExtension>
      </CustomAction>
    </Elements> 
    

    RegistrationID should be the ID of the document set content type that you want this ribbon button to appear on. 0x0120D520 is the base document set content type ID; this ribbon button will appear on all document set content types.

    Location specifies the document set ribbon tab.

    Image16by16 and Image32by32 point to images located in the /_layouts/images folder on the server. You can specify your own image files.

    LabelText, ToolTipTitle, and ToolTipDescription are text strings used for the ribbon title and tool tip.

    CommandAction specifies what the ribbon button actually does. In this example, ECMAScript (JavaScript, JScript) uses a posts back event in the DownloadZipDelegateEvent.

    Feature.xml

    <?xml version="1.0" encoding="utf-8"?> 
    <!-- _lcid="1033" _version="14.0.3427" _dal="1" -->
    <!-- _LocalBinding -->
    <!-- Copyright (c) Microsoft Corporation. All rights reserved. -->
    <Feature xmlns="https://schemas.microsoft.com/sharepoint/" 
    Id="{CC06B38F-B9AB-4227-841C-DC9F438345A7}"
    Title="Add new button"
    Description="Add new button to ribbon" 
    Version="1.0.0.0"
    Scope="Web"
    Hidden="TRUE">
        <ElementManifests>
            <ElementManifest Location="element.xml" />
        </ElementManifests>
    </Feature>
     
    

    After you add these files to the folder, activate the feature by running the following commands.

    stsadm.exe –o installfeature –filename adddocsetribbon\feature.xml
    stsadm.exe –o activatefeature –filename adddocsetribbon\feature.xml –url "http://<server>"
    

    Replace http://<server> with the location of the Web where you want to activate your feature. After the feature is installed, navigate to a document set and click the Document Set ribbon tab to see your button.

Download the Document Set as a .ZIP File

  1. Use the Microsoft.Office.DocumentManagement.DocumentSets object model to create a delegate event that gets the current SPList item and gets the document set. This example uses the MyRibbonDelegate event.

    using System;
    using Microsoft.SharePoint;
    using Microsoft.Office.DocumentManagement.DocumentSets;
    using System.Web.UI.WebControls;
     
    namespace MyRibbonDelegate
    {
        public class MyRibbonDelegateClass : WebControl
        { 
            protected override void OnLoad(EventArgs e)
            {
                this.EnsureChildControls();
                base.OnLoad(e);
    if (this.Page.Request["__EVENTTARGET"] == "DownloadZipDelegateEvent")
                {
    SPListItem currentItem = SPContext.Current.ListItem;
    DocumentSet currentDocset = DocumentSet.GetDocumentSet(currentItem.Folder);
    this.Page.Response.ContentType = "application/zip";
    currentDocset.Export(this.Page.Response.OutputStream, 1024);
    this.Page.Response.End();
                }
            }
        }
    }
    
    

    When the page request event target is equal to the delegate event, then the code executes and gets the current SPListItem and gets the document set. The Export() method for the document set is called and specified by the OutputSteam parameter for the page, which gets the files within the document set. For export, there is a second parameter that is an int set to 1024. Setting the int in increaments of 1024 enables you to specify the value in MB that can be exported. If there is more than 1 GB of files inside the document set, the event fails.

  2. Click the custom button that you created in the first procedure to call this code. A dialog box appears that prompts you to open or save the document set as a .zip package.

See Also

Concepts

Document Sets in SharePoint Server 2010 (ECM)

Developing with Document Management Features in SharePoint Server 2010 (ECM)