jacksorjacksor (Richard Jackson)
09/12/2023, 4:30 PMId
of /Blog-1/
so that I can then put images there through MediaService.
My current approach is some sort of loop where I start at GetRootMedia, then find the "Blog" folder by name, then find the child folder by getting the ancestors of that folder, like this:
var nameOfRootFolder = "Blog";
var nameOfChildFolder = "Blog-1";
var folder = MediaService.GetRootMedia().FirstOrDefault(x => x.Name.Equals(nameOfRootFolder));
var childrenFolder =
MediaService.GetAncestors(folder).FirstOrDefault(x => x.Name.Equals(nameOfChildFolder));
...but that feels bad and, irrespective of any performance issues, wouldn't work past one child folder.
So like, what should I do? Is this also an examine query off? And if it is an examine query, could someone give me an example of how I'd find a folder by path?
Yours truly,
Someone who found out that MediaService existed about 3 hours ago.Mike Chambers
09/12/2023, 4:36 PMnodeName
= Blog-1
and __NodeTypeAlias
of Folder
..
will get you the id, or guid __Key
of the media folderjacksorjacksor (Richard Jackson)
09/12/2023, 4:37 PMMike Chambers
09/12/2023, 4:40 PMjacksorjacksor (Richard Jackson)
09/12/2023, 4:40 PMMike Chambers
09/12/2023, 4:46 PMUmbraco.Cms.Core.Constants.UmbracoIndexes.ExternalIndexName
Umbraco.Cms.Infrastructure.Examine.IndexTypes.Media
{ModelsBuilderNamespace}.Folder.ModelTypeAlias
Mike Chambers
09/12/2023, 4:47 PMresults.ToPublishedSearchResults(_publishedSnapshotAccessor.GetRequiredPublishedSnapshot())
rather than looping through the results with the yield return _umbracoHelper.Content(id);Mike Chambers
09/12/2023, 4:48 PMjacksorjacksor (Richard Jackson)
09/12/2023, 4:54 PMIEnumerable<string> ids = Array.Empty<string>();
if (_examineManager.TryGetIndex("ExternalIndex", out var index))
{
ids = index.Searcher.CreateQuery("media")
.NodeTypeAlias("folder")
.And()
.Field("nodeName", "Blog-1")
.Execute()
.Select(x => x.Id);
}
A hub and casual space for you to interact with fellow community members and learn more about Umbraco!
Powered by