Export (0) Print
Expand All
Expand Minimize
9 out of 11 rated this helpful - Rate this topic

Adding Custom Quick Access Buttons to the Page Editing Toolbar in SharePoint Server 2007

SharePoint 2007

Summary: Learn how to create and add custom buttons to the Quick Access button area of the Page Editing toolbar used in Microsoft Office SharePoint Server (MOSS) 2007 Web content management (WCM) sites.

Office Visual How To

Applies to: Microsoft Office SharePoint Server 2007, Microsoft Visual Studio 2005

Andrew Connell, Critical Path Training, LLC (Microsoft MVP)

January 2008

Overview

All Microsoft Office SharePoint Server 2007 Web content management (WCM) or publishing sites use the Page Editing toolbar. The Page Editing toolbar provides content authors, owners, and editors with functionality to manage content pages on a site. One of the sections in the Page Editing toolbar—the Quick Access button area—displays buttons for context-sensitive items that are available to authors based on the current state of the page. Developers are free to customize the Quick Access button area, and create custom Quick Access buttons.

Code It

Quick Access buttons in the Page Editing toolbar are founded on the concept of actions. Actions, also known as console actions, can be created by developers to provide a specific type of control.

First, create an action by creating a class that inherits from the Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ConsoleAction class. The custom class then overrides many methods and properties to define the conditions when the button should appear. For example, the UserRights property is a bitwise flag that specifies what permissions the user must have to see the button. The RequiresStates property is another bitwise flag that dictates under what conditions the button should appear.

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.WebControls;
using Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions;

namespace MSDN.SharePoint.Samples {
  public class PublishingPagePropertiesAction : ConsoleAction {
    private string _imageUrl;

    public PublishingPageDetailAction ()
      : base() {
      this.DisplayText = "Page Properties";
    }

    public override SPBasePermissions UserRights {
      get { return SPBasePermissions.EmptyMask; }
    }

    public override AuthoringStates RequiredStates {
      get { return AuthoringStates.EditingMenuEnabled; }
    }

    public override string ImageUrl {
      get {
        if (string.IsNullOrEmpty(_imageUrl))
          return "~/_layouts/images/info16by16.gif";
        else return _imageUrl;
      }
      set { _imageUrl = value; }
    }

    public override string NavigateUrl {
      get {
        PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(SPContext.Current.Web);
        string query = string.Format("<Where><Eq><FieldRef Name=\"ID\" /> _
           <Value Type=\"Counter\">{0}</Value></Eq></Where>", SPContext.Current.ListItem.ID);
        PublishingPage page = pubWeb.GetPublishingPages(query)[0];
        return String.Format("javascript:window.location= _
           '{0}/{1}/Forms/DispForm.aspx?ID={2}&RootFolder={3}';",
          page.PublishingWeb.Url.ToString(),
          page.ListItem.ParentList.RootFolder.Url.ToString(),
          page.ListItem.ID.ToString(),
          page.ListItem.ParentList.RootFolder.Url.ToString());
      }
    }
  }
}

The last property, NavigateUrl, contains the work payload of the button. When the button is clicked, the NavigateUrl property is used to determine what should happen.

Implementation

After you create the button class, and sign and deploy the assembly to the global assembly cache, the next step is to make the SharePoint publishing site aware of the new button. The Quick Access buttons on the Page Editing toolbar are defined by the QuickAccess.xml file, located in the path [..]\12\TEMPLATE\LAYOUTS\EditingMenu. However, developers should not modify this file. Instead, the QuickAccess.xml file points to the CustomQuickAccess.xml file in the Master Page Gallery of each SharePoint publishing site collection. This file contains a reference that points to the custom console action class and an assembly that contains the class, very much like the <% @Register %> directive in an ASPX or ASCX file. After the reference, the CustomQuickAccess.xml file includes a section declaring the console action, as shown in the following code.

<?xml version="1.0" encoding="utf-8" ?>
<Console>
  <references>
    <reference TagPrefix="msdn"
               assembly="MSDN.SharePoint.Samples, Version=1.0.0.0, Culture=neutral, 
                 PublicKeyToken=c591e70cfdf9ce4f"
               namespace="MSDN.SharePoint.Samples" />
  </references>
  <structure>
    <ConsoleNode Sequence="1"
                 ConfigMenu="Add"
                 HideStates="PageHasCustomizableZonesFalse|PageHasFieldControlsFalse"
                 Action="msdn:PublishingPagePropertiesActions"
                 ID="msdnPublishingPagePropertiesActionQuickAccessButton" />
  </structure>
</Console>
Read It

This article demonstrates how to create and add custom buttons to the Quick Access button area of the Page Editing toolbar used in MOSS 2007 Web content management sites. Following are the steps to create a custom button:

  1. In Visual Studio, create a Class Library project.

  2. Add references to the required assemblies to the Visual Studio project.

  3. Create a class that inherits from the Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ConsoleAction class.

  4. Override necessary methods on the derived ConsoleAction class.

  5. Build and deploy the signed assembly that contains the derived ConsoleAction class to the server’s global assembly cache.

  6. Modify the CustomQuickAccess.xml file to register the new button and notify MOSS about it.

See It

Add Quick Access Buttons to Page Editing Toolbar

Watch the Video

Video Length: 00:13:09

File Size: 11.4 MB WMV

Explore It
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.