Get All iamges of the current libarary
In Image Content I have Multiple Libaries
Library 1
Library 2
Library 3
In Library 2 I have other Libaries with name
Sub Library One
Sub Library Two
Sub Library Three
I have a custom module in which i have selected one image from the Sub Library Two
Now in my logic i have to get all the images of the libary(Sub Library Two) where my particular image is present.
In my code when i try to get image object it shows it's Parent as Library2 instead of Sub Library Two
var objPhotoContent = item.GetValue<ContentLink[]>("Photo");
if (objPhotoContent != null)
LibrariesManager libManager = LibrariesManager.GetManager();
var img = libManager.GetImage(objPhotoContent[0].ChildItemId);//or should i use objPhotoContent[0].Id
//var imagesofCurrentLibrary = App.WorkWith().Images()
// .Where(w => w.Parent == img.Parent && w.Status == ContentLifecycleStatus.Live)
// .Get();
There is a distinction between an Album (root image library) and IFolder (sub image libraries)
maybe this code steers you in the right direction,
you can probably ignore the multisite stuff
public static IFolder GetFolder(string folderId)
var currentSiteProviders = SystemManager.CurrentContext.CurrentSite.GetProviders("Telerik.Sitefinity.Modules.Libraries.LibrariesManager").Select(p => p.ProviderName); foreach (string provName in currentSiteProviders) LibrariesManager mgr = LibrariesManager.GetManager(provName); try IFolder folder = mgr.GetFolder(new Guid(folderId)); return folder; catch (Exception ex) return null;public static List<IFolder> GetChildFolders(IFolder folder) var currentSiteProviders = SystemManager.CurrentContext.CurrentSite.GetProviders("Telerik.Sitefinity.Modules.Libraries.LibrariesManager").Select(p => p.ProviderName); foreach (string provName in currentSiteProviders) LibrariesManager mgr = LibrariesManager.GetManager(provName); try List<IFolder> list = mgr.GetChildFolders(folder).ToList(); return list; catch (Exception ex) return null;
Thanks Ernesto Lopez,
But here I still understand that how can I get all images of current folder from a image.
Let's say My question is like I have a image in my Dynamic Module which is selected from a sub library of an image library. What i need is the list of all the images of that sub library via help of that image.
Hello Kamran,
Please note that all the child libraries in the top level library are considered folders. So, if you would like to get the images from a nested library (folder), you can first get the folderId from the image and then find the folder by folderId and query the images under this folder.
Here is a sample code on how you can get the images under a nested library (folder):
var folderId = image.FolderId;
public static IQueryable<Telerik.Sitefinity.Libraries.Model.Image> GetImagesByFolderId(Guid? folderId) LibrariesManager librariesManager = LibrariesManager.GetManager(); var images = librariesManager.GetImages().Where(i => i.FolderId == folderId); return images; var images = librariesManager.GetImages().Where(i => i.Album.Id == albumId);Thanks a lot .Now will try to use it. Also have to sort the images under the folder.Let's see