Accessing Image from Library

Posted by Community Admin on 04-Aug-2018 21:09

Accessing Image from Library

All Replies

Posted by Community Admin on 03-Jun-2013 00:00
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.
Posted by Community Admin on 04-Jun-2013 00:00
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()
Posted by Community Admin on 04-Jun-2013 00:00
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
Posted by Community Admin on 04-Jun-2013 00:00
Thanks - that was it!
Posted by Community Admin on 26-Oct-2016 00:00

[quote]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.
[/quote]

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;
           
       

This thread is closed