Copied to clipboard

Flag this post as spam?

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


  • Tor Langlo 151 posts 400 karma points
    Apr 29, 2019 @ 05:02
    Tor Langlo
    0

    Get IContent from ContentService by url/path

    I'm trying to find a node which is not published yet, so I'm thinking I need to use the ContentService. All I know about the content is its url, e.g. "/home/products/myproductname"

    How can I find that node?

    -Tor

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Apr 29, 2019 @ 06:04
    Dave Woestenborghs
    0

    Hi Tor,

    I'm a bit confused. You say your content is unpublished, but you want to get it by url.

    A content item that is not published does not have URL. So the content service does not support getting a item by url

    Dave

  • Tor Langlo 151 posts 400 karma points
    Apr 29, 2019 @ 06:50
    Tor Langlo
    0

    Change URL to path then. Clearly the node has a position in the tree, from which you can deduct the path (and url) from.

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Apr 29, 2019 @ 07:34
    Dave Woestenborghs
    100

    Hi Tor,

    That is not supported.

    Here is the docs for the content service : https://our.umbraco.com/apidocs/csharp/api/Umbraco.Core.Services.ContentService.html#UmbracoCoreServicesContentServiceGetByLevelSystemInt32_

    So I see 2 options.

    • You use the content service to iterate over your tree. If you have a lot of content items this may not be the best approach performance wise.
    • You query the internal examine index base on your url segments. The internal index contains also unpublished items

    So if you go the examine way you could start with finding the node on productname (your last url segment)

    var searcher = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"];

    var criteria = searcher.CreateSearchCriteria();

    criteria.RawQuery("urlName:myproductname");

    var searchResults = searcher.Search(criteria);

    If that only has one result you can be pretty sure you have the correct page. If not you can always use the parentId of the results to find the correct parent item

    Dave

  • Nathan Woulfe 422 posts 1580 karma points MVP 3x c-trib
    Apr 29, 2019 @ 08:16
    Nathan Woulfe
    0

    Alternate option: if you can get the node at /home/products (by content type or a known document id/udi) you could then iterate the children.

    Wouldn't be as performant as using Examine, but depending on the number of nodes being queried that may not be an issue. If you're using ContentService this shouldn't be happening on the forward-facing site, so performance again could be less of a concern.

  • Tor Langlo 151 posts 400 karma points
    Apr 29, 2019 @ 19:08
    Tor Langlo
    0

    Ok, thanks guys. I will give both options, a) search the examine index, and b) try to find the parent node and if found iterate the children, a try.

    -Tor

  • 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