Copied to clipboard

Flag this post as spam?

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


  • Luke 110 posts 256 karma points
    Oct 22, 2014 @ 11:21
    Luke
    0

    Application Event

    I have written a class that extends ApplicationEventHandler in order to catch the publish event of certain document types.

    I am struggling to find the documentation for V7. I originally used Document.AfterPublish but noticed this is obsolete. As such I used Umbraco.Core.Services.ContentService.Published += Content_Published; I'm I correct to use this?

    Also I placed the class in the App_Code folder, any other suggestions on where to place the class? (in terms of standards)

    Thank you as always!

  • Dan Lister 416 posts 1974 karma points c-trib
    Oct 22, 2014 @ 11:44
    Dan Lister
    0

    Hi L,

    You are indeed correct to use the Published event on the Content Service class. You can place the class where ever fits within your website. Generally, I develop an additional class library to contain things such as Event Handlers but App_Code will work fine in your instance.

    Thanks, Dan.

  • Luke 110 posts 256 karma points
    Oct 22, 2014 @ 11:51
    Luke
    0

    Hi Dan,

    Many thanks for your answer. Perfect!

    Regards, L

  • Luke 110 posts 256 karma points
    Oct 22, 2014 @ 11:52
    Luke
    0

    Sorry Dan,

    Any resources for V7 you know about with examples?

    Regards, L

  • Dan Lister 416 posts 1974 karma points c-trib
    Oct 22, 2014 @ 11:55
    Dan Lister
    0

    Hi L,

    Here is an example I've used in the past. Although it uses the Saved event, the Published event should be similar.

    Thanks, Dan.

  • Sören Deger 733 posts 2844 karma points c-trib
    Oct 22, 2014 @ 12:01
    Sören Deger
    0

    Hi L,

    you can find another example for using events in Umbraco 7 into my uNewsManager package:
    http://our.umbraco.org/projects/website-utilities/unewsmanager

    It includes a .cs-File with a good example to startup with eventhandling in umbraco.

    Sören

  • Luke 110 posts 256 karma points
    Oct 22, 2014 @ 12:04
    Luke
    0

    Perfect Soren,

    Just had a look, perfect examples of what I was looking for.

    Regards, L

  • Luke 110 posts 256 karma points
    Oct 22, 2014 @ 12:32
    Luke
    0

    Hi Dan, Soren,

    I saw your comments on a post from June about determining if the entity is new. I could not see the IsNewEntity() as part of the ContentService.Published so I used node.HasIdentity; is this acceptable/best way to see if the entity is new?

    Also does the ContentService.Saved fire as when someon saves and publishes?

    Sorry no more questions I promise :-)

  • Sören Deger 733 posts 2844 karma points c-trib
    Oct 22, 2014 @ 13:41
    Sören Deger
    0

    Hi L,

    I think the best way to do this is to use node.HasIdentity(). Another way is to use the IRememberBeingDirty interface, in ContentService.Saved event i.e:

    foreach (var node in e.SavedEntities)
    {
    // Check if node is still created
            var dirty = (IRememberBeingDirty)node;
            var isNew = dirty.WasPropertyDirty("Id");
    
    if (isNew) {
    // do anything
    }

    Hope this help you.


    Sören 

  • Luke 110 posts 256 karma points
    Oct 22, 2014 @ 16:54
    Luke
    0

    Thank you Soren, I have used methodology.

    L

Please Sign in or register to post replies

Write your reply to:

Draft