Copied to clipboard

Flag this post as spam?

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


  • Graham Carr 277 posts 389 karma points
    Sep 03, 2014 @ 17:09
    Graham Carr
    0

    Automated publishing, no UmbracoContext?

    I am running the following piece of code on the ContentService_Publishing event which works fine when I click Publish from the CMS however it fails when it is called via an automated publish from a publish At date/time being set on a node as the UmbracoContext is returned as null.

    Any ideas of why and a way around it?

            void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs<IContent> e)
            {
                foreach(var node in e.PublishedEntities)
                {
                    if (node.ContentType.Alias == "Vacancy" && node.Parent().Name == "Pending" && node.Status != ContentStatus.Trashed)
                    {
                        var _contentService = Umbraco.Core.ApplicationContext.Current.Services.ContentService;
                        UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current);
                        var parent = helper.ContentSingleAtXPath("//VacancySchool[@urlName='" + node.Parent().Parent().Name.ToUrlSegment() +"']/VacancyStatus[@nodeName='Live']");
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies