Copied to clipboard

Flag this post as spam?

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


  • Dawid 21 posts 131 karma points
    26 days ago
    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 4265 posts 15409 karma points
    20 days ago
    Alex Skrypnyk
    0

    Hi Dawid

    Try this one:

    helper.NiceUrl(id)
    

    Alex

  • Alex Skrypnyk 4265 posts 15409 karma points
    6 days ago
    Alex Skrypnyk
    0

    Hi Dawid,

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

    /Alex

  • John Bergman 289 posts 804 karma points
    6 days ago
    John Bergman
    0

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

  • Dawid 21 posts 131 karma points
    5 days ago
    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 21 posts 131 karma points
    5 days ago
    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