using media folder to get images

Vote:
 

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.

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

Any help than can be given will be greatly appreciated. 

#111773
Oct 21, 2014 11:02
Vote:
 

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:

@Url.ContentUrl(image.ContentLink)
#111777
Oct 21, 2014 11:55
Vote:
 

Thank you so much that worked like a charm!! 

#111778
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.