Get all Media from a Folder

Hi,

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>b__93_1(IPublishedSnapshot publishedShapshot, Boolean previewing, Int32 id)\r\n at Umbraco.Web.PublishedCache.NuCache.PublishedContent.d__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.get_Items()

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 …

Thanks,


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/97633-get-all-media-from-a-folder