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

Forums / Developing with Sitefinity / Get Image Album By Name

Get Image Album By Name

15 posts, 0 answered
  1. Henriette
    Henriette avatar
    41 posts
    Registered:
    20 Aug 2009
    15 Feb 2013
    Link to this post

    Hi all

    I'am trying to get an Image album by it's name instead of the GuidId. The documentation describes the below code to get the album by its guid, but i would like to get the album by it's name. Is that possible?

    LibrariesManager librariesManager = LibrariesManager.GetManager();    
    Album album = librariesManager.GetAlbums().Where(a => a.Id ==albumId).FirstOrDefault();     
    return album;

  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    15 Feb 2013 in reply to Henriette
    Link to this post

    Hey Hendrik,

    Sure, you can just filter on the 'Title' property of a Library like this:

    var librariesManager = LibrariesManager.GetManager();
    var album = librariesManager.GetAlbums().Where(a => a.Title == "your-album-title").FirstOrDefault();
    return album;
     

    Regards,
    Daniel

  3. Henriette
    Henriette avatar
    41 posts
    Registered:
    20 Aug 2009
    15 Feb 2013 in reply to Daniel Plomp
    Link to this post

    Hallo Daniel
    Many many thanks for your reply. I will try this. :-)

    Best regards
    Henrik Stensgaard, Net-ressourcer.dk


  4. Henriette
    Henriette avatar
    41 posts
    Registered:
    20 Aug 2009
    15 Feb 2013 in reply to Henriette
    Link to this post

    Hallo again
    I'am struggling a little with this code in VB. If I translate it, it will be 

    librariesManager__1.GetAlbums().Where(Function(a) a.Title = "your-album-title").FirstOrDefault()

    but the problem is that visual studio complains with "where cannot be called with these arguments. " How can this be done in VB?

    Many thanks in advance

    Henrik Stensgaard

  5. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    15 Feb 2013 in reply to Henriette
    Link to this post

    Hi Hendrik,

    This worked for me:

    Dim librariesManager = LibrariesManager.GetManager()
    Dim album = librariesManager.GetAlbums().Where(Function(a) a.Title = "your-album-title").FirstOrDefault()
    Return album

    I also tried to convert it with the Code Converter that Telerik offers.

    Regards,
    Daniel

  6. Henriette
    Henriette avatar
    41 posts
    Registered:
    20 Aug 2009
    18 Feb 2013 in reply to Daniel Plomp
    Link to this post

    Hallo again

    Sorry but this dosent work, still the same error.  Am i doing something wrong here?

    best regards

    Henrik stensgaard

  7. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    19 Feb 2013 in reply to Henriette
    Link to this post

    Hi Hendrik,

    I think this code should work.

    Dim manager As LibrariesManager = LibrariesManager.GetManager()
    Dim album = manager.GetAlbums().Where(Function(a) a.Title.Value = "your-album-title").FirstOrDefault()

    The 'Title' property is of type LString, which is used for the multilingual features. So you need to use the Value property of the LString.

    Let me know if that works for you?

    Kind regards,
    Daniel

  8. Henriette
    Henriette avatar
    41 posts
    Registered:
    20 Aug 2009
    19 Feb 2013 in reply to Daniel Plomp
    Link to this post

    Hallo Daniel

    You are just the best, it works now fine. Thank you many many times. If you ever viset Denmark, please let me know and I will buy you at big beer :-)

    Best regards
    Henrik

     

     

  9. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    19 Feb 2013 in reply to Henriette
    Link to this post

    Hi Hendrik,

    Sounds great! :)
    Glad it worked for you.

    Cheers!
    Daniel

  10. Henriette
    Henriette avatar
    41 posts
    Registered:
    20 Aug 2009
    19 Feb 2013 in reply to Daniel Plomp
    Link to this post

    Hallo Daniel

    Sorry to get back with this again, I was a little to quick with the good news. This still dosent work. The error is ex = {"Property 'System.String Value' is not defined for type 'System.String'"} when I use the a.Title.Value. I also tryed .tostring without luck.

    Dosent there exists any documentation on the GetAlbums filter function, or maby you know what table the album is stored in, so I can find the guidid?

    Best regards

    Henrik

  11. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    19 Feb 2013 in reply to Henriette
    Link to this post

    Hi Hendrik,

    What version and edition are you using right now?

    Regards,
    Daniel

  12. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    19 Feb 2013 in reply to Daniel Plomp
    Link to this post

    Okay, this is probably a VB.NET thing.

    While C# allows the comparing of LString with string directly, in VB you have to explicitly complare the Value property of the LString type with the parameter. But that isn't enough apparently.

    Try this code, it works on my side :)

    Public Shared Function GetAlbum(name As String) As Album
        
       Dim manager As LibrariesManager = LibrariesManager.GetManager()
       Dim album = manager.GetAlbums().FirstOrDefault(Function(a) a.Title.Equals(name))
       Return album
     
    End Function

    Regards,
    Daniel

  13. Henriette
    Henriette avatar
    41 posts
    Registered:
    20 Aug 2009
    19 Feb 2013 in reply to Henriette
    Link to this post

    Hallo again

    Thanks again. Now it works as expexted.

    Many many thanks

    Best regards
    Henrik

  14. Eric
    Eric avatar
    60 posts
    Registered:
    24 Feb 2011
    27 Aug 2013 in reply to Daniel Plomp
    Link to this post
    I got it to work in VB like this (pretty much the same)
    Dim libman = LibrariesManager.GetManager()
     
    Dim album = libman.GetAlbums().Where(Function(t) CType(t.Title, String) = sLibraryName).FirstOrDefault()

    HOWEVER - One thing I can't figure out ... If you nest a library within a library... it returns nothing.  I'm not sure what the Title would be of a nested library.
  15. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    Registered:
    06 Dec 2016
    28 Aug 2013
    Link to this post
    Hi,

    The Library itself is a very heavy persistent object and is related to many others (permissions, blob storage providers, etc.). If it were made hierarchical, the complexity of managing permissions and persisting multiple of these objects would grow. Since customers mainly asked about being able to organize things in a hierarchy, 6.0 introduces a Folder object. There is not distinction between a Folder and a Library in the UI, however there is a difference. The Folder is a very light thing, which was introduced for the sole purpose of holding hierarchical relationships.

    Please check the samples provided in the following documentation section:

    http://www.sitefinity.com/documentation/documentationarticles/managing-folders

    Regards,
    Stefani Tacheva
    Telerik
    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
15 posts, 0 answered