Share via


ConsoleAction Class

Base class that represents an action that is displayed in the Editing Menu and other action user interfaces (UIs).

Inheritance Hierarchy

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ConsoleAction
        

Namespace:  Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

Syntax

'Declaration
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public MustInherit Class ConsoleAction _
    Inherits WebControl _
    Implements IPostBackEventHandler
'Usage
Dim instance As ConsoleAction
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public abstract class ConsoleAction : WebControl, 
    IPostBackEventHandler

Remarks

Action UIs such as the Editing Menu, Quick Access Menu, or Site Actions menu present various actions to the user. Each of these menus contains an instance of the ConsoleDataSource object that provides a hierarchical collection of ConsoleNode objects, some of which specifically implement the T:Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ConsoleAction class. Each implementation of this class represents a specific action, such as Create Page, Publish, Show Version History, or Save and Stop Editing.

The code example presented here is simplified, but shows how a console action should be constructed. Running this sample application adds a "Save and Stop Editing" button to the Quick Access Menu. It requires that the page be in Edit mode and that the user have EditListItem permissions to this PublishingPage object. The sample uses JavaScript to post back to this control, and when it raises a postback event, the event saves the current T:Microsoft.SharePoint.Publishing.PublishingPage object and shows the saved page in display mode.

Examples

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Publishing;
using Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions;
using Microsoft.SharePoint.Publishing.WebControls;

namespace PageEditingToolbarMenuItemControls
{
    /// Adds a button to the Quick Access toolbar that checks in
    /// a document that is checked out by another user.
    public sealed class DiscardOtherUserCheckoutAction : ConsoleAction
    {
        /// This is the constructor of the specific ConsoleAction
        public DiscardOtherUserCheckoutAction()
            : base()
        {
            this.DisplayText = "Discard Other User’s Checkout";
        }
        /// SPBasePermissions are required to use this Console Action.
        /// <value></value>
        public override SPBasePermissions UserRights
        {
            get { return SPBasePermissions.CancelCheckout; }
        }
        /// Checks for the AuthoringStates required to enable the
        /// button.
        /// <value></value>
        public override AuthoringStates RequiredStates
        {
            get
            {
                return AuthoringStates.CheckedOutVersionExistsTrue | AuthoringStates.IsCheckedOutToCurrentUserFalse | AuthoringStates.IsDocLibListItemTrue;
            }
        }
        /// Defines the PostBack behavior when the URL for this control is clicked.
        /// <param name="eventArgument"></param>
        public override void RaisePostBackEvent(string eventArgument)
        {
            if (eventArgument == DiscardOtherUserCheckoutAction.DiscardCheckOutPostBackEventArgument)
            {
                try
                {
                    SPFile myFile = SPContext.Current.File;
                    myFile.UndoCheckOut();
                }
                catch (SPException e)
                {
                    ConsoleNode actionsNode = new ConsoleNode();
                    ConsoleNode exitNoSaveNode = new ConsoleNode(actionsNode);
                    exitNoSaveNode.Action = new ExitWithoutSavingAction();
                    exitNoSaveNode.Action.ID = "checkOutDiscardErrorActionExitNoSave";
                    actionsNode.ChildConsoleNodes.Add(exitNoSaveNode);
                    this.ShowError(e, new ConsoleError(e.Message, actionsNode));
                }
                finally
                {
                    ConsoleAction.RefreshCurrentItemAfterUpdate();
                }
            }
        }
        /// Specifies the URL for this Console Action.
        /// <value></value>
        public override string href
        {
            get
            {
                return "javascript:" + Page.ClientScript.GetPostBackEventReference(this, DiscardOtherUserCheckoutAction.DiscardCheckOutPostBackEventArgument);
            }
        }
        private const string DiscardCheckOutPostBackEventArgument = "discardUserCheckout";
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

ConsoleAction Members

Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions Namespace

ConsoleNode

ConsoleDataSource

IsCurrentlyEnabled

RaisePostBackEvent

RefreshCurrentItemAfterUpdate

ShowError

Inheritance Hierarchy

System.Object
  System.Web.UI.Control
    System.Web.UI.WebControls.WebControl
      Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ConsoleAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ApproveOrDeclineAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.BaseApproveAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.BaseDeclineAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.BrowseWebPartsAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CancelApprovalRequestAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CancelApprovalWorkflowRequestAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CancelSchedulingAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CheckInAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CheckInWithCommentAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CheckOutAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CheckOutOverrideAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CopyAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CreateNewPublishingPageAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CreateNewSiteAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CreateNewsLinkAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CreatePageVariationAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.CreateSiteVariationAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.DeleteAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.EditPropertiesAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ExitMenuAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ExitWithoutSavingAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ForceSavePublishingPageAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ImportWebPartsAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ManageSiteAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ModifyNavigationAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ModifyPagesLibrarySettingsAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.MoveAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.OneClickPublishAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.PersonalViewAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.PreviewAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.PreviewExistingPublishingPageAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.PublishAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.PublishWithCommentAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.QuickDeployAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ReviewPublishingPageAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.RevisionHistoryAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.SavePublishingPageAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.SearchWebPartsAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.SharedViewAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ShowUnapprovedResourcesAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.SiteDirectoryBrokenLinksCheckerAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.SiteSettingsAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.SpellCheckEntirePageAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.SwitchToAuthoringModeAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.SwitchToPublishedModeAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.UndoCheckOutAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.UnpublishAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.UpdateVariationsAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.VersionDifferenceAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.VersionInfoAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ViewAllSiteContentAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.ViewRecycleBinAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.WorkflowStartAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.WorkflowStatusAction
        Microsoft.SharePoint.Publishing.WebControls.EditingMenuActions.WorkflowTasksAction