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 Team,
I want to access all Media that exists in perticular folder. To access i have only folder name not id for any thing..either Images or folder.
Also I want to access that media(Images) public URL so that i can access that image in browser or html(by assign href in img).
Please help me in this.
You will need to inject IMediaTypeService and IMediaService
Then the following code should give you what you want, I can't say it is the correct or best way, but should work ok :)
@{ var folderType = mtype.Get("folder"); var folders = mediaService.GetPagedOfType(folderType.Id, 0, 20, out var total).Where(m => m.Name == NAMEOFYOURFOLDER); var enumerableFolders = folders as IMedia[] ?? folders.ToArray(); if (enumerableFolders.Any()) { @foreach (var folder in enumerableFolders) { var imagesInFolder = mediaService.GetPagedChildren(folder.Id, 0, 50, out var totalimages); <ul class="list-unstyled"> @foreach (var image in imagesInFolder) { dynamic umbracoFile = JsonConvert.DeserializeObject(image.GetValue<string>(Constants.Conventions.Media.File)); <li>@umbracoFile.src</li> } </ul> } } }
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
How to get Media using MediaService
Hi Team,
I want to access all Media that exists in perticular folder. To access i have only folder name not id for any thing..either Images or folder.
Also I want to access that media(Images) public URL so that i can access that image in browser or html(by assign href in img).
Please help me in this.
You will need to inject IMediaTypeService and IMediaService
Then the following code should give you what you want, I can't say it is the correct or best way, but should work ok :)
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.