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

Forums / Developing with Sitefinity / Accessing Image from Library

Accessing Image from Library

5 posts, 0 answered
  1. Robert Rohrman
    Robert Rohrman avatar
    3 posts
    Registered:
    23 Apr 2009
    03 Jun 2013
    Link to this post
    Hello -

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

    Everywhere I look - this should work, however it always returns the following error...
    Property 'System.String Value' is not defined for type 'System.String'


    any help would be much appreciated.
  2. Arno
    Arno avatar
    249 posts
    Registered:
    08 Sep 2010
    04 Jun 2013
    Link to this post
    Hi Robert,

    The problem is that Title is of type Lstring, and "Ads" is of type string. VB.NET has a problem with that, even if you use the Value property which is a string. I don't know the details, but you can try this:

    Dim manager As LibrariesManager = LibrariesManager.GetManager()
    Dim album = manager.GetAlbums().Where(Function(a) a.Title.Equals("Ads")).FirstOrDefault()
  3. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    04 Jun 2013 in reply to Arno
    Link to this post
    Hi Robert,

    Arno is given the correct solutions. This is a VB.NET thing. While C# allows the comparing of LString with string directly, in VB.NET 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

    Kind regards,
    Daniel

    * If this post helped you, please mark it as answered
  4. Robert Rohrman
    Robert Rohrman avatar
    3 posts
    Registered:
    23 Apr 2009
    04 Jun 2013 in reply to Arno
    Link to this post
    Thanks - that was it!
  5. David
    David avatar
    0 posts
    Registered:
    23 Aug 2016
    26 Oct in reply to Daniel Plomp
    Link to this post

    Daniel Plomp said:Hi Robert,

    Arno is given the correct solutions. This is a VB.NET thing. While C# allows the comparing of LString with string directly, in VB.NET you have to explicitly complare the Value property of the LString type with the parameter. But that isn't enough apparently.

    Hi Daniel,

    It's apparently not just a VB.NET thing - I'm trying to do the same sort of thing in C#, and having no luck.

    I try Title=="name", I get an error about comparing LString to String.

    I try Title.Value=="name", I get an error about String not having a Value method. 

    I try Title.Equals("name"), I get no match (even though there is an album with that name).

    I've also tried both GetAlbums().Where(...).FirstOrDefault() and GetAlbums().FirstOrDefault(...) - no difference.

    Here's the current version of my function:

            protected bool ImageExists(string imageName)
            {
                try
                {
                    LibrariesManager librariesManager = LibrariesManager.GetManager();
                    Album album = librariesManager.GetAlbums().FirstOrDefault(a => a.Title.Equals("Banners"));
                    Image image = null;
                    if (album != null)
                        image = album.Images().FirstOrDefault(i => i.Title.Equals(imageName));
                    return (image != null);
                }
                catch (Exception)
                {
                    throw;
                }
            }

5 posts, 0 answered