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.
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
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.
is working on a reply...