Copied to clipboard

Flag this post as spam?

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


  • alex 10 posts 80 karma points
    Dec 15, 2016 @ 10:01
    alex
    0

    Trying to get node url from published event

    Hi,

    I am trying to get the node url during the published event, so that I can send an email to the user informing them that a new item has been published and can be accessed through the url. However, the problem is that node which is of type IContent does not return a url. I have tried to get url using UmbracoHelper.Url(node.Id) which only returns "#" and also tried UmbracoHelper.TypedContent(node.Id).UrlAbsolute() which returns a null exception error.

    Here is the code that i am using:

        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            ContentService.Published += contentServicePublished;
        }
    
        private void contentServicePublished(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
    
            foreach (var node in e.PublishedEntities)
            {
                if (node.IsNewEntity())
                {
                    var umbraco = new UmbracoHelper(UmbracoContext.Current);
    
                    //when an open calls tender is published
                    if (node.ContentType.Alias == ConstantValues.Document_Type_Alias_Tender &&
                        node.ParentId == ConstantValues.OpenCallPageId)
                    {
                        sendEmailsForOpenCallsTenders(umbraco, node);
                    }
                }
            }
        }
    
    
        private static void sendEmailsForOpenCallsTenders(UmbracoHelper umbraco, IContent node)
        {
    
            var emailService = IocHelpers.Container.GetInstance<IEmailService>();
            var umbracoHelperService = IocHelpers.Container.GetInstance<IUmbracoHelperService>();
            var razorEngineCompileTemplate = IocHelpers.Container.GetInstance<IRazorEngineCompileTemplate>();
    
            var eventEmailPlaceholder = (SubscriptionTypeData) umbraco
                .TypedContent(ConstantValues.EmailOutlookRefreshSubscriptionTypeId);
    
    
            var url = umbraco.Url(node.Id); //returns #
            var test = umbraco.TypedContent(node.Id).UrlAbsolute(); //returns null exception
        }
    

    My question is:

    Is there a way to get the url from a node of type IContent in the published event or does a different event need to be used?

    Thanks in advance for your help.

Please Sign in or register to post replies

Write your reply to:

Draft