What event is raised when a page is published and how do I capture it? - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

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?
  • 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

  • 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
     
  • That looks like precisely what I need. I'll try it in a few hours. Thanks!

  • 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.

  • 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.