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.
I have a part of URL , like 'book/audiobook/nestedaudioboook/teststructure/' (book - is not root, it's the secont level under the root). I need to find node id to get IPublishedContent. I'he written the method
public static IContent GetChildContentByName(IEnumerable<IContent> rootContentNodes, string param) { if (string.IsNullOrEmpty(param)) return null; string[] names = param.Split('/').Where(p=> !string.IsNullOrEmpty(p)).ToArray(); if (names == null || names.Length == 0) return null; var key = param.Replace('/', '-'); HttpContext context = HttpContext.Current; if (context.Cache[key] == null) { try { IContent content =GetContent(names, rootContentNodes.SelectMany(cnt => cnt.Children()).ToList(), 0); var expTime = DateTime.Now.AddMinutes(1); if (content!=null && Ozon.Shop.Common.SiteSettings.Cache) { expTime = DateTime.Now.AddMinutes(15); } context.Cache.Insert(key, content, null, expTime,Cache.NoSlidingExpiration, CacheItemPriority.Normal, null); return content; } catch (Exception) { return null; } } return (IContent) context.Cache[key]; }
private static IContent GetContent(string[] names,List<IContent> contentNodes, int index) { var content = contentNodes.Single(ch => ch.Name.ToLower() == names[index]); return (names.Length <= ++index) ? content : GetContent(names, content.Children().ToList(), index); }
Is there any methods to do that?
You can use uQuery for that. There is a method to get a node by Url.
http://our.umbraco.org/documentation/Reference/Querying/uQuery/Content/Nodes
Dave
Thanks, Dave. It's wonderful.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Get IPublishedContent by part of Url from service
Hello.
I have a part of URL , like 'book/audiobook/nestedaudioboook/teststructure/' (book - is not root, it's the secont level under the root). I need to find node id to get IPublishedContent. I'he written the method
Is there any methods to do that?
You can use uQuery for that. There is a method to get a node by Url.
http://our.umbraco.org/documentation/Reference/Querying/uQuery/Content/Nodes
Dave
Thanks, Dave. It's wonderful.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.