1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / App.WorkWith().Albums().Images broken in 5.1?

App.WorkWith().Albums().Images broken in 5.1?

5 posts, 1 answered
  1. Chris Hayward
    Chris Hayward avatar
    36 posts
    Registered:
    17 Dec 2009
    06 Aug 2012
    Link to this post
    From this link:
    http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/modules/media-modules/images/managing-albums/querying-albums 


    Upgrading to 5.1 seems to have broken  the ability to do App.WorkWith().Albums().Images

    'Telerik.Sitefinity.Libraries.Model.Album' does not contain a definition for 'Images' and no extension method 'Images' accepting a first argument of type 'Telerik.Sitefinity.Libraries.Model.Album' could be found (are you missing a using directive or an assembly reference?)

    thx


  2. Chris Hayward
    Chris Hayward avatar
    36 posts
    Registered:
    17 Dec 2009
    06 Aug 2012
    Link to this post
    Oops, let me clarify, it's done by this exact code.


        public static List<Telerik.Sitefinity.Libraries.Model.Image> GetImagesByAlbumName(string albumName)
        {
            var album = App.WorkWith().Albums().Where(a => a.Title == albumName).Get().FirstOrDefault();

            if (album != null)
                return album.Images.Where(x => x.Status == ContentLifecycleStatus.Live && x.Visible).OrderBy(x => x.Ordinal).ToList();
            else
                return new List<Telerik.Sitefinity.Libraries.Model.Image>();
        }


    album.Images generates the error.
  3. Chris Hayward
    Chris Hayward avatar
    36 posts
    Registered:
    17 Dec 2009
    09 Aug 2012
    Link to this post
    Bumping.  

    how do i retreive images from an album by album name?

    thx
  4. Randy Hodge
    Randy Hodge avatar
    96 posts
    Registered:
    03 Nov 2014
    14 Aug 2012
    Link to this post
    Hi, Chris.

    In order to decrease the consumed memory and increase the overall performance of Sitefinity, several properties (in-memory collections) of given classes were replaced with extension methods that return the same data via IQueryable collections. See this page from the documentation.

    One of these was the Album class. So Images is now an extension method of Album as shown here.

    So your code needs to change just a bit:
    public static List<Telerik.Sitefinity.Libraries.Model.Image> GetImagesByAlbumName(string albumName)
        {
            var album = App.WorkWith().Albums().Where(a => a.Title == albumName).Get().FirstOrDefault();
     
            if (album != null)
                return album.Images().Where(x => x.Status == ContentLifecycleStatus.Live && x.Visible).OrderBy(x => x.Ordinal).ToList();
            else
                return new List<Telerik.Sitefinity.Libraries.Model.Image>();
        }

    Make sure to add this using statement:
    using Telerik.Sitefinity.Modules.Libraries;

    This should get you back in business.

    Kind regards,
    Randy Hodge
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  5. Chris Hayward
    Chris Hayward avatar
    36 posts
    Registered:
    17 Dec 2009
    14 Aug 2012
    Link to this post
    Much appreciated, thanks for that link. 

    cheers,
    Chris


5 posts, 1 answered