Copied to clipboard

Flag this post as spam?

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


  • CM 4 posts 94 karma points
    Nov 23, 2016 @ 10:47
    CM
    0

    Read Content Tree in Publish EventHandler

    Hi All In the ContentService.Published event handler is there a way of getting the full path of the published entity in the content tree e.g. If I have a content tree of webpages/homefolder/home and I publish the "home" content file I would get "webpages/homefolder"

    Thanks!

  • John Hesman 8 posts 99 karma points
    Nov 23, 2016 @ 11:36
    John Hesman
    100

    In the published event one of the arguments is the PublishEventArgs

    you can use this to get the content item

    e.PublishedEntities will contain the list of entities that have been published allowing you to then use the umbraco helper to get at any of the data you need.

    you can get the site id by splitting the content item path variable

    and so get the url using the NiceUrl method from the umbraco helper object.

    e.g.

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);    
    var contentId = int.Parse(contentItem.Path.Split(',')[1]);
    var contentUrl = umbracoHelper.NiceUrl(contentId);
    

    I don't know if this is the best way but it should get the job done.

  • CM 4 posts 94 karma points
    Nov 24, 2016 @ 15:45
    CM
    0

    That works a treat! Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft