Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

using media folder to get images


Hello All! 

I'm relatively new to episerver and was hoping someone could help. 

I am trying to get a list of images to show in a gallery by selecting a media folder. Now at the moment I can select the folder however I am at a lost to how to pull the images within the folder. 

Below is the code I have at the moment.

Name = "Folder",
GroupName = SystemTabNames.Content,
Order = 1)]
public virtual ContentReference Folder { get; set; }

Any help than can be given will be greatly appreciated. 

Oct 21, 2014 11:02

Assuming you have ImageFiles setup as a media type (e.g. there is a content type code file called "ImageFile") You can use an IContentRepository to get a list of the images, e.g.

var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();

            var galleryImages = contentRepository.GetChildren<ImageFile>(Folder);

You can use a UrlResolver to get the actual Url of the image:

var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();

foreach (var image in galleryImages)
     var url = urlResolver.GetUrl(image.ContentLink);

Or if you are in an MVC Razor View you can use the URL helper:

Oct 21, 2014 11:55

Thank you so much that worked like a charm!! 

Oct 21, 2014 12:21
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.