How to add Custom Quick Access Buttons to the Page Editing Toolbar in SharePoint Server 2007 Publishing Page?
Explanation:
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.
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
Code:
The below code is used to add a "Preview" button to the Page Editing Toolbar
public class PublishingPagePreview : ConsoleAction { private string _imageUrl; public override string DisplayText { get { return "Preview"; } set { base.DisplayText = value; } } 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/prvw_imf.gif"; else return _imageUrl; } set { _imageUrl = value; } } public override string NavigateUrl { get { PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(SPContext.Current.Web); return "javascript:if(!g_previewRequested){g_previewRequested=true;__doPostBack('ctl00$ctl07$saPreview_CmsActionControl','previewPage');}"; } } }
Xml:
Go to Site Settings > Master Page Gallery > Editing Menu Folder
Edit the CustomQuickAccess.xml, check in the file and make sure to approve it.
<?xml version="1.0" encoding="utf-8" ?> <Console> <references> <reference TagPrefix="customButton" assembly="[AssemblyName], Version=1.0.0.0, Culture=neutral, PublicKeyToken=[Token]" namespace="[NameSpace]" /> </references> <structure> <ConsoleNode Sequence="198" Action="customButton:PublishingPagePreview" DisplayText="Preview" UseResourceFile="false" ID="qaPreviewAllData"/> </structure> </Console>
References: http://msdn.microsoft.com/en-us/library/bb986730.aspx
No comments:
Post a Comment