Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello,
Does anyone know how can I get the node ID from an url using C# ?
Thanks
http://grail-technology.co.uk/blog/get-node-by-url might help you :)
ohh thanks, was searching for this all day :)
Umbraco Comunity is amazing!
The url above is down. Can any of you repost the solution?
Thanks!
Hi Anders,
Not sure if this was the solution proposed, but there's a method in uQuery.GetNodeByUrl() which is in the umbraco namespace.
HTH,
Hendy
Isn't uQuery a part of uComponents?The version i'm on ATM for this site is 4.7, and i can't seem to find the uQuery namespace in umbraco.
And i dont want to install uComponents. There has to be some other way?
uQuery was moved into core, so should be available in the umbraco namespace (from the umbraco.dll assembly)
But that was in v4.8, right?
arh yes, you're correct, from v4.8 onwards.
@Anders - no love for uComponents? :-(
The original link is still available via archive.org: http://web.archive.org/web/20120123141406/http://www.grail-technology.co.uk/blog/get-node-by-url/
Alternatively, feel free to check the uQuery source (either uComponents or Umbraco core) and rip out the "GetNodeByUrl" code. :-)
Cheers, Lee.
@Lee, of course! But since it's quite big i don't want to install it for a single method.
Thanks for the link!: )
Apologise for the link being down, had major issues with hosting provider so left and given I hadn't had any traffic to my site in forever didn't rush to bring it back up.
@Lee thanks bailing me out :)
No worries - I totally appreciate that it's a big library, and overkill for what you want to achieve!
If you've got your own code library, then do feel free to rip out any parts of uComponents code - it's all MIT licensed. :-)
Cheers
Just going to paste the code in here for future reference:
public int GetNodeIdFromUrl(string url) { int nodeId = -1; string xpathUrl = url == "/" ? "home" : url; string xpath = String.Format("//node[@urlName='{0}']", xpathUrl); var node = GetXmlNodeByXPath(xpath); if (node != null && node.Count > 0) { while (node.MoveNext()) { var currentnode = node.Current.GetAttribute("id", ""); int.TryParse(currentnode, out nodeId); } } return nodeId; } private XPathNodeIterator GetXmlNodeByXPath(string xpathQuery) { XPathNavigator xp = content.Instance.XmlContent.CreateNavigator(); if (xp != null) return xp.Select(xpathQuery); return null; }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Get Node ID from URL
Hello,
Does anyone know how can I get the node ID from an url using C# ?
Thanks
http://grail-technology.co.uk/blog/get-node-by-url might help you :)
ohh thanks, was searching for this all day :)
Umbraco Comunity is amazing!
The url above is down.
Can any of you repost the solution?
Thanks!
Hi Anders,
Not sure if this was the solution proposed, but there's a method in uQuery.GetNodeByUrl() which is in the umbraco namespace.
HTH,
Hendy
Isn't uQuery a part of uComponents?
The version i'm on ATM for this site is 4.7, and i can't seem to find the uQuery namespace in umbraco.
And i dont want to install uComponents.
There has to be some other way?
Hi Anders,
uQuery was moved into core, so should be available in the umbraco namespace (from the umbraco.dll assembly)
But that was in v4.8, right?
arh yes, you're correct, from v4.8 onwards.
@Anders - no love for uComponents? :-(
The original link is still available via archive.org: http://web.archive.org/web/20120123141406/http://www.grail-technology.co.uk/blog/get-node-by-url/
Alternatively, feel free to check the uQuery source (either uComponents or Umbraco core) and rip out the "GetNodeByUrl" code. :-)
Cheers, Lee.
@Lee, of course! But since it's quite big i don't want to install it for a single method.
Thanks for the link!
: )
Apologise for the link being down, had major issues with hosting provider so left and given I hadn't had any traffic to my site in forever didn't rush to bring it back up.
@Lee thanks bailing me out :)
No worries - I totally appreciate that it's a big library, and overkill for what you want to achieve!
If you've got your own code library, then do feel free to rip out any parts of uComponents code - it's all MIT licensed. :-)
Cheers, Lee.
Cheers
Just going to paste the code in here for future reference:
is working on a reply...