Copied to clipboard

Flag this post as spam?

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


  • nojaf 91 posts 300 karma points
    Jan 02, 2014 @ 10:00
    nojaf
    0

    Get Url with UmbracoHelper

    Hi,

    I'm trying to get the url of an IPublishedContent with the UmbracoHelper inside an UmbracoApiController.

    the query:

    UmbracoHelper uh = new UmbracoHelper(base.UmbracoContext);
    var foundOffices = uh.TypedContentAtXPath("//Office[zip= '" + cityZip + "']");
    

    I get results for foundOffices but when I try to say

    foreach(var item in foundOffices)
    {
        Log(item.Url);
    }
    

    It says:

    Cannot resolve a Url for a content item with a null UmbracoContext.Current reference
    

    Any suggestions?

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 02, 2014 @ 12:09
    Jeroen Breuer
    0

    Maybe try this to create the UmbracoHelper:

    var uh = new UmbracoHelper(Umbraco.Web.UmbracoContext.Current);

    Jeroen

  • nojaf 91 posts 300 karma points
    Jan 02, 2014 @ 14:17
    nojaf
    0

    Still getting the error but not always.

    Could this be an internal cache error?

  • Charles Afford 1163 posts 1709 karma points
    Jan 05, 2014 @ 21:38
    Charles Afford
    0

    Hi, What are you trying to achive with this?  Maybe there is another way :).  Thanks,  Charlie

    UmbracoHelper uh =newUmbracoHelper(base.UmbracoContext);
    var foundOffices = uh.TypedContentAtXPath("//Office[zip= '"+ cityZip +"']");
  • nojaf 91 posts 300 karma points
    Jan 06, 2014 @ 15:17
    nojaf
    0

    What does it look like I'm trying to achieve?

    I want to get the url of a document where the zip property is whatever is in cityZip.

  • Charles Afford 1163 posts 1709 karma points
    Jan 06, 2014 @ 18:05
    Charles Afford
    1

    Well if you wanted help the reply was 

    I want to get the url of a document where the zip property is whatever is in cityZip.

    Good luck :).  Charlie

  • nojaf 91 posts 300 karma points
    Jan 07, 2014 @ 17:16
    nojaf
    102

    Ok, the answer to the problem is calling the

    Umbraco.Web.UmbracoContext.EnsureContext()
    

    Method before trying to get the url.

Please Sign in or register to post replies

Write your reply to:

Draft