Trouble getting images from Sitefinity galleries

Posted by Community Admin on 04-Aug-2018 15:27

Trouble getting images from Sitefinity galleries

All Replies

Posted by Community Admin on 11-Apr-2011 00:00

I am having an issue with a RadRotator user control that I created. Basically whenever I run the following bit of code, all images in the gallery appear twice. I have the same  issue with a similar query for the news items.

 

 

 

var images = App.WorkWith().Albums().Where(a => a.Title == title).Get().FirstOrDefault().Images;

 

 

 

 

foreach (Telerik.Sitefinity.Libraries.Model.Image i in images)

 

 

 

 

 

Hashtable ht = new Hashtable();

 

 

ht.Add(

 

"Url", i.MediaUrl);

 

 

ht.Add(

 

"Title", i.Title.ToString());

 

 

results.Add(ht);

 

Thanks for your help,
Wes

Posted by Community Admin on 11-Apr-2011 00:00

Hello Wesley,

You need to get only the Live status of the images - you can specify this in your code like this:

var images = App.WorkWith().Albums().Where(a => a.Title == title).Get().FirstOrDefault().Images.Where(i => i.Status == ContentLifecycleStatus.Live);
The reason why you're getting them doubled do far is because if you do not explicitly specify otherwise you will get all images in the album which contains other states (e.g Master, Temp)

Best wishes,
Boyan Barnev
the Telerik team

Posted by Community Admin on 11-Apr-2011 00:00

Thanks, I knew it had to be a simple answer!

This thread is closed