Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Umbraco - Select node by URL

Tags:

c#

xpath

umbraco

I'm having issues with Umbraco when trying to get access to a node by it's url.

I've been trying to form an xpath query to select on the url, but I've no idea how to do that, and everything in their API is a 'dynamic' so I'm finding it impossible to dig much deeper for other methods.

The "Link to document" property in the Umbraco editor shows the path to be "/links/link-regions/link-region-1/". Its location in the editor is "/Data/Links/Link Regions/Link Region 1".

I suspect it'll look like this, but I cna't make it work:

//*[@url='/links/link-regions/link-region-1/']

I basically want to know what I have to do to get the node by providing either of these values and no others. I've been trying to do this for days now to no avail, please help!

like image 565
brins0 Avatar asked Jun 27 '14 11:06

brins0


1 Answers

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.

like image 199
Jamie Howarth Avatar answered Nov 17 '22 00:11

Jamie Howarth