Get Image Album By Name
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;
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
Hallo Daniel
Many many thanks for your reply. I will try this. :-)
Best regards
Henrik Stensgaard, Net-ressourcer.dk
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
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
Hallo again
Sorry but this dosent work, still the same error. Am i doing something wrong here?
best regards
Henrik stensgaard
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
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
Hi Hendrik,
Sounds great! :)
Glad it worked for you.
Cheers!
Daniel
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
Hi Hendrik,
What version and edition are you using right now?
Regards,
Daniel
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
Hallo again
Thanks again. Now it works as expexted.
Many many thanks
Best regards
Henrik
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.
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