I am currently in need of a way to get a page id from a Url. I have found plenty of old topics relating to this issue, but none that provided an answer that seemed to work for me.
If I've got this Url: /sample/url/node/ the only way I could find to fetch the associated node's id would be to do something like:
If you're using Umbraco 4.11 or later, there are a new set of APIs that allow you to retrieve strongly-typed content (as opposed to dynamic - which can be frustrating when trying to evaluate types when debugging).
UmbracoContext.Current.ContentCache.GetByRoute(string url) should do what you want.
Getting Node from Url
Good afternoon,
I am currently in need of a way to get a page id from a Url. I have found plenty of old topics relating to this issue, but none that provided an answer that seemed to work for me.
If I've got this Url: /sample/url/node/ the only way I could find to fetch the associated node's id would be to do something like:
Umbraco.TypedContentSingleAtXPath("//*[@urlName='sample']/*[@urlName='url']/*[@urlName='node']").Id
However, something tells me that I'm probably over complicating it.
Any help would be very much appreciated!
Thanks,
Matt
Hey,
You can use umbraco.uQuery.
Look out when you want to use it in Umbraco 6.2.6. My website is stoping when I call this method.
If you're using Umbraco 4.11 or later, there are a new set of APIs that allow you to retrieve strongly-typed content (as opposed to dynamic - which can be frustrating when trying to evaluate types when debugging).
is working on a reply...