More in this section
Forums / Developing with Sitefinity / What event is raised when a page is published and how do I capture it?

What event is raised when a page is published and how do I capture it?

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
5 posts, 1 answered
  1. Scott
    Scott avatar
    3 posts
    Registered:
    23 Jun 2014
    02 Sep 2014
    Link to this post

    Hi,

    I've been searching and testing for hours. When a user publishes a page (a new page or an update to an existing page) I want to respond with a process that inspects the PageNode and PageData that has been published.
    What is the event I need to respond to? I'll avoid mentioning what I've tried so that it doesn't confuse the question. When a new page or an update to an existing page has been published, what event can I subscribe to or what method on what class do I need to override so that I can obtain the ID of the updated PageNode?

    Thanks

  2. Pavel Benov
    Pavel Benov avatar
    341 posts
    Registered:
    14 Mar 2016
    04 Sep 2014
    Link to this post
    Hi Scott,

    You can try on PageManager.Executing through the Bootstrapper like so:

    protected void Application_Start(object sender, EventArgs e)
            {
                Bootstrapper.Initialized += Bootstrapper_Initialized;
            }
     
            void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
            {
                if (e.CommandName == "Bootstrapped")
                {
                    PageManager.Executing += new EventHandler<Telerik.Sitefinity.Data.ExecutingEventArgs>(PageManager_Executing);
                }
            }
     
            private void PageManager_Executing(object sender, Telerik.Sitefinity.Data.ExecutingEventArgs e)
            {
                if (e.CommandName == "CommitTransaction" || e.CommandName == "FlushTransaction")
                {
                    var provider = sender as PageDataProvider;
                    var dirtyItems = provider.GetDirtyItems();
                    if (dirtyItems.Count != 0)
                    {
                        foreach (var item in dirtyItems)
                        {
                            //Can be New, Updated, or Deleted
                            SecurityConstants.TransactionActionType itemStatus = provider.GetDirtyItemStatus(item);
                            var page = item as PageDraft;
                            if (page != null)
                            {
                                if (itemStatus == SecurityConstants.TransactionActionType.New
                                    || itemStatus == SecurityConstants.TransactionActionType.Updated)
                                {
                                    //Edit Page
                                    if (page.IsTempDraft)
                                    {
                                        //plug your logic here
                                    }
     
                                    //Publish Page
                                    if (!page.IsTempDraft)
                                    {
                                        //plug your logic here
                                    }
     
                                }
                            }
                        }
                    }
                }
            }

    I hope this helps.

    Regards,
    Pavel Benov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Scott
    Scott avatar
    3 posts
    Registered:
    23 Jun 2014
    04 Sep 2014 in reply to Pavel Benov
    Link to this post

    That looks like precisely what I need. I'll try it in a few hours. Thanks!

  4. Scott
    Scott avatar
    3 posts
    Registered:
    23 Jun 2014
    04 Sep 2014 in reply to Pavel Benov
    Link to this post

    That worked perfectly.  I stepped through it as I created and edited a few pages and it enabled me to isolate exactly what I'm looking for.

    Thanks again.

    Answered
  5. Sudesh
    Sudesh avatar
    1 posts
    Registered:
    15 Jul 2015
    15 Jul 2015
    Link to this post
    hi , i have used the above code to find out which page is being published. The if(!page.istempdraft) block runs when i provide the schedule timings for a page. I have not published the page at this point. I have just set the time, sitefinity automatically refreshes and the control goes inside the if block. Is there a way to prevent this scenario and make it run only when the publish event happens at the scheduled time or if it manually published.
5 posts, 1 answered