Copied to clipboard

Flag this post as spam?

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


  • Dawid 26 posts 136 karma points c-trib
    Jan 24, 2018 @ 13:36
    Dawid
    0

    UmbracoHelper.TypedContent returns null for new document in GetheringNodeData

    I'm using Umbraco version 7.6.11.

    In GatheringNodeData event I'm trying to collect the Urllink and add it to Index. To get the Url I need to get IPublishedContent object. To get that I've tried to us the UmbracoHelper.TypedContent. ![enter image description here][1]

    Item is visible in the database

    var person = umbracoHelper.TypedContent(nodeData.Fields["id"]);
    UmbracoContext context;
    if (UmbracoContext.Current == null)
    {
       var worker = new SimpleWorkerRequest("/", string.Empty, new StringWriter());
       var httpContext = new HttpContext(worker);
       var dummyContext = new HttpContextWrapper(httpContext);
    
       context = UmbracoContext.EnsureContext(
           dummyContext,
           ApplicationContext.Current,
           new WebSecurity(dummyContext, ApplicationContext.Current),
                        false);
     }
     else
     {
          context = UmbracoContext.Current;
     }
    
     var helper = new UmbracoHelper(context);
     person = helper.TypedContent(nodeData.NodeId);
    
     if (nodeData.Fields.ContainsKey("content") && nodeData.Fields.ContainsKey("id") && person != null)
    

    Person is null. This Document exists in database but doesn't exists in the umbraco.Config file, so I guess it is not in the Content cache.

    I cannot use the ApplicationContext.Current.Services.ContentService.GetById(nodeData.NodeId), becuase I will not get the Url to the document.

    What I'm doing wrong? Can I get the Url in other way ?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jan 30, 2018 @ 13:22
    Alex Skrypnyk
    0

    Hi Dawid

    Try this one:

    helper.NiceUrl(id)
    

    Alex

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Feb 13, 2018 @ 14:43
    Alex Skrypnyk
    0

    Hi Dawid,

    Did you find a solution? Share with our community, please

    /Alex

  • John Bergman 483 posts 1132 karma points
    Feb 14, 2018 @ 05:29
    John Bergman
    0

    In your first line, what type of object is nodeData? Do you have property converters turned on?

  • Dawid 26 posts 136 karma points c-trib
    Feb 14, 2018 @ 07:45
    Dawid
    0

    The nodeData variable is of type : IndexingNodeDataEventArgs. No I dont have property converter turned on. How can I benefit from the property converter?

  • Dawid 26 posts 136 karma points c-trib
    Feb 14, 2018 @ 07:49
    Dawid
    0

    So my solution to this was using ContentService and used ToUrlSegment method as it seems that I don't need full url, but only current page url segment.

    So I guess I could get rid of the ContentService method and just base on the nodeData variable.

Please Sign in or register to post replies

Write your reply to:

Draft