May 1, 2012
(0 votes)

EPiServer Workflow Replacement : Step 6 - Hooking the Ready to Publish Event

This is the last in a series of posts about how my company built a replacement workflow platform for EPiServer. Why we chose to do this is explained here: http://world.episerver.com/Blogs/Hans/Dates/2012/4/EPiServer-Workflow-Replacement--Step-1Explanation-and-Disabling-Edit-Tab/

I’ve covered why we had to build our own workflow. I’ve gone into how to disable the base Workflow tab and replace it with your own GuiPlugin named Workflow. I’ve explained from the top down how this all works from a user/admin perspective, I’ve shown what database fields need to be updated to reject pages – and I’ve given you a workaround to disable that pesky Save and Publish button.

The only other critical component to this entire process is the ability  to notify approvers whenever a page is marked “Ready to Publish”. To do this, we create a new class and hook into the DataFactory.Instance.CheckingInPage event like so:

First – I create a new class : I named mine CustomPageActionControl.cs. I then designate it as a [PagePlugIn] and set up the Initialize method..this is where we hook CheckingInPage – in this instance by calling an additional class called NotifyApprovers.

    public class CustomPageActionControl
        public static void Initialize(int bitflags)
            DataFactory.Instance.CheckingInPage += NotifyApprovers;

(As a side note, this is really handy for doing all sorts of other things..most of our sites also hook DataFactory.Instance.SavedPage, PublishedPage, DeletingPage, MovingPage, etc – there are all sorts of things you can hook into: http://sdk.episerver.com/library/cms5/html/AllMembers_T_EPiServer_DataFactory.htm )


Anyway..our NotifyApprovers method performs thusly:

  1. We get a working version of the page information that we want to send on – PageVersionURL, Approver User Names, etc..
  2. We iterate through an array of all access control entities, check their roles (in this instance they have to have LANGUAGE_EN-US or the correct locale access – so we don’t send our European users information about approving US Locale specific information) and getting a list of all users who can approve
  3. We email out all approvers with information about the page (as seen in step #3)


The below should be cleaned up and made more DRY (i.e. take advantage of LINQ), but you get the idea..


 private static void NotifyApprovers(object sender, PageEventArgs e)
            String ApproverUserNames = "";
            List<String> EmailList = new List<String>();
            String PageVersionUrl = ConfigurationManager.AppSettings["BaseUrl"] + e.Page.LinkURL;
            PageVersionUrl = PageVersionUrl.Replace("&epslanguage", "_" + e.Page.WorkPageID + "&idkeep=True&epslanguage");

            foreach (EPiServer.Security.RawACE Ace in e.Page.ACL.ToRawACEArray()) // Get array of all access control entries
                EPiServer.Security.AccessControlEntry EAC = new EPiServer.Security.AccessControlEntry(Ace);
                if ((Ace.Access & EPiServer.Security.AccessLevel.Publish) == EPiServer.Security.AccessLevel.Publish) //Only look at users who have access to publish page
                    foreach (System.Web.Security.MembershipUser AllUsers in Membership.GetAllUsers())
                        if (Roles.IsUserInRole(AllUsers.UserName, "LANGUAGE_" + (Convert.ToString(e.Page.LanguageID)).ToUpper())) // User has locale access
                            if (Roles.IsUserInRole(AllUsers.UserName, Ace.Name))
                            { //user has publish access for this page
                                if (!EmailList.Contains(AllUsers.Email.ToString())) //only add users once
                                    ApproverUserNames += UserProfileTools.GetFullName(AllUsers.UserName.ToString()) + "; ";


            String EmailBody = "<h2>EPiServer Approval Requested: Page Ready to Publish</h2><table style=\"font-family: Arial; font-size: 12px; \"><tr><td><b>Title:</b></td><td>" + e.Page.PageName + "</td></tr><tr><td><b>Submitter:</b></td><td>" + UserProfileTools.GetFullName(e.Page.ChangedBy) + "</td></tr><tr><td><b>Version URL:</b></td><td>" + PageVersionUrl + "</td></tr><tr><td><b>Published URL:</b></td><td>" + ConfigurationManager.AppSettings["BaseUrl"] + e.Page.LinkURL + "</td></tr><tr><td><b>Necessary Action:</b></td><td>This page is ready for your approval. Please log into EPiServer and visit the <i>Ready to Publish URL</i> specified above. For your reference, the current published page version is also available by visiting the <i>Published Version URL</i>." + "</td></tr><tr><td><b>Content Approvers:</b></td><td>" + ApproverUserNames + "</td></tr></table>";
            if (EmailList.Count() > 0)
               EmailTools.SendTemplatedEmail("EPiServer Page Approval Request – www.mysite.com", EmailBody, EmailList, "EPiServer@episerver.com", "EPiServer");



And that’s it! When an editor hits “Ready to Publish”, all of the approvers are automatically notified that they need to go in and check out the content.

That sums up our custom workflow application. If you found it at all useful in any respect (or if you feel like pointing out my errors in logic and/or code) I’d love to hear from you in the comments below.

May 01, 2012


Aug 22, 2017 09:20 PM


misor aliya
misor aliya Jun 1, 2018 10:15 AM


nick010 Jul 11, 2018 09:16 PM

Jawaharlal Nehru Technological University, Kakinada is a public university, in Kakinada, East Godavari district, north of the Indian state of Andhra Pradesh. It is one of India's leading universities focusing on engineering for more JNTUK

Please login to comment.
Latest blogs
Content Delivery API – The Case of the Duplicate API Refresh Token

Creating a custom refresh provider to resolve the issues with duplicate tokens in the DXC The post Content Delivery API – The Case of the Duplicate...

David Lewis | Sep 29, 2022 | Syndicated blog

New Optimizely certifications - register for beta testing before November 1st

In January 2023, Optimizely is making updates to the current versions of our certification exams to make sure that each exam covers the necessary...

Jamilia Buzurukova | Sep 28, 2022

Optimizely community meetup - Sept 29 (virtual + Melbourne)

Super excited to be presenting this Thursday the 29th of September at the Optimizely community meetup. For the full details and RSVP's see the...

Ynze | Sep 27, 2022 | Syndicated blog

Preview multiple Visitor Groups directly while browsing your Optimizely site

Visitor groups are great - it's an easy way to add personalization towards market segments to your site. But it does come with it's own set of...

Allan Thraen | Sep 26, 2022 | Syndicated blog