Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 954 karma points
    Jan 08, 2014 @ 00:51
    Tom
    0

    Get Node ID from incoming url? v6/v7 back-end

    In c# I was just wondering in v7 or v6 how you'd be able to get a node id if you have a url?

     

    Cheers

  • Tony 2 posts 23 karma points
    Jan 08, 2014 @ 02:37
    Tony
    0

    I've just been trying to find out the very same thing, and getting nowhere fast. The only thing I've come up with is to compare against the Url property of every content object. How you get a list of every content object is another matter - I can't find any in built way of doing that either, so the best I can manage is to recurse down from the root nodes, like:

    Func<IPublishedContent, IEnumerable<IPublishedContent>> getDescendants = null;
    getDescendants = x => x.Children.Concat(x.Children.SelectMany(y => getDescendants(y)));
    var rootContent = Umbraco.TypedContentAtRoot();
    var allContent = rootContent.Concat(rootContent.SelectMany(x => getDescendants(x)));
    var myNode = allContent.Single(x => x.Url == "/myurl");

    ...which I don't imagine is very efficient and I don't know where that leaves you vis-a-vis unpublished or deleted content either. There is a IsDraft field, but that always seems to be false which I've just posted a question about.

    Anyway, hopefully (surely?) there's some better built in way of doing it, and I too would very much like to find out what it is.

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft