Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ansar 181 posts 291 karma points
    Feb 14, 2014 @ 15:12
    Ansar
    0

    ApplicationBase events - V 7.0.3

    Hi,

    I am trying to attach the following events but couldnt get it working. 

    Document.New

    and

    Document.BeforePublish

    Tried with ApplicationBase, ApplicationStartupHandler and IApplicationEventHandler but none of it worked.

    Can anyone please provide the correct way for this in Umbraco 7.

    Thanks in advance

  • Damiaan 439 posts 1293 karma points MVP 4x c-trib
    Feb 14, 2014 @ 16:25
    Damiaan
    101

    Hi,

    You should be able to get it working with ApplicationEventHandler and the "Published" event from the contentService. This is working code in a v7 website we have:

    public class DateFolderEvents : ApplicationEventHandler
    {    
      protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
      {
         Umbraco.Core.Services.ContentService.Published += ContentService_Published;
         base.ApplicationStarted(umbracoApplication, applicationContext);
      }
      private void ContentService_Published(Core.Publishing.IPublishingStrategy sender, Core.Events.PublishEventArgs<Core.Models.IContent> e)
      {
        foreach (var content in e.PublishedEntities)
        {
           PublishDoc(content);
        }
      }
    
      private void PublishDoc(IContent sender)
      {
         var user = new User(sender.CreatorId);
         // do your stuff
      }
    }
    
  • Ken Schnell 35 posts 146 karma points
    Aug 04, 2020 @ 16:07
    Ken Schnell
    0

    For others working with Umbraco 8 you can see this link: https://our.umbraco.com/documentation/reference/events/application-startup

  • Ansar 181 posts 291 karma points
    Feb 14, 2014 @ 17:41
    Ansar
    0

    Thanks a lot Damiaan.. It worked like a charm :)

  • Damiaan 439 posts 1293 karma points MVP 4x c-trib
    Feb 14, 2014 @ 17:44
    Damiaan
    0

    Don't forget to mark the reply as answer. It's not because we are friendly, we don't like karma ;-)

Please Sign in or register to post replies

Write your reply to:

Draft