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
I'm trying to get images from a folder I've set up in the Media section.
I'm using Umbraco.MediaAtRoot() which is returning the root media correctly, however when trying to access the media in a folder (using .Children) I'm getting the following Error:
'Object Reference not set to an instance of an object'
The stacktrace is as follows:
Umbraco.Web.PublishedCache.NuCache.PublishedContent.<>c.<.cctor>b931(IPublishedSnapshot publishedShapshot, Boolean previewing, Int32 id)\r\n at Umbraco.Web.PublishedCache.NuCache.PublishedContent.19.MoveNext()\r\n at System.Linq.Buffer1..ctor(IEnumerable1 source)\r\n at System.Linq.OrderedEnumerable1.<GetEnumerator>d__1.MoveNext()\r\n at System.Linq.SystemCore_EnumerableDebugView1.getItems()
1.<GetEnumerator>d__1.MoveNext()\r\n at System.Linq.SystemCore_EnumerableDebugView
Does anyone know what is causing this error and how it can be resolved? Or is there a better way to achieve what I am trying to do? It feels like something that should be fairly simple so not sure if I'm missing something ...
Why dont you create instance of MediaService and se GetRootMedia() function to get your Media folder by name and use .Children to fetch all images.
var _mediaService = ApplicationContext.Services.MediaService;
var _mediaFolder = (IPublishedContent)_mediaService.GetRootMedia().FirstOrDefault(x => x.Name.InvariantEquals("MyImages"));
Hope that helps.
Could you share the full code that you're using to retrieve your folder? It might give a better understanding of what's going wrong.
Similarly, you can also see my solution here in how to retrieve children from a media folder (using a media picker in V8).
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted