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
Hi,
I need to get a list of the latest 10 items added to the entire media tree, not from a specific folder.
I want to do this in a partial view macro using razor.
Is there a quick way to do this?
thanks,
nick
You can do it with Examine
@{ var searcher = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"]; var searchCriteria = searcher.CreateSearchCriteria(); var results = searcher.Search(searchCriteria.RawQuery("nodeTypeAlias:Image")); if (results != null && results.Any()) { var resultsOrdered = results.OrderByDescending(x => DateTime.ParseExact(x.Fields["createDate"], "yyyyMMddHHmmssfff", System.Globalization.CultureInfo.CurrentCulture)); var resultsTop10 = resultsOrdered.Take(10); foreach (var result in resultsTop10) { @result.Fields["nodeName"] } } }
Hi Soren,
That's great. Solution is working nicely. Thanks for your help.
I amended slightly to get the URL of the File items:
var results = searcher.Search(searchCriteria.RawQuery("nodeTypeAlias:File")); if (results != null && results.Any()) { var resultsOrdered = results.OrderByDescending(x => DateTime.ParseExact(x.Fields["updateDate"], "yyyyMMddHHmmssfff", System.Globalization.CultureInfo.CurrentCulture)); var resultsTop5 = resultsOrdered.Take(5); foreach (var result in resultsTop5) { var med = Umbraco.Media(result.Fields["id"].ToString()); string url = @med.umbracoFile; //var url = result.Fields["urlName"].ToString(); <li><a href="@url">@result.Fields["nodeName"]</a></li> } }
cheers,
Nick
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Get latest media items from entire media tree
Hi,
I need to get a list of the latest 10 items added to the entire media tree, not from a specific folder.
I want to do this in a partial view macro using razor.
Is there a quick way to do this?
thanks,
nick
You can do it with Examine
Hi Soren,
That's great. Solution is working nicely. Thanks for your help.
I amended slightly to get the URL of the File items:
cheers,
Nick
is working on a reply...