Get All iamges of the current libarary

Posted by Community Admin on 04-Aug-2018 08:10

Get All iamges of the current libarary

All Replies

Posted by Community Admin on 06-May-2014 00:00

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();                

           

Posted by Community Admin on 07-May-2014 00:00

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;

 

Posted by Community Admin on 07-May-2014 00:00

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.

Posted by Community Admin on 09-May-2014 00:00

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;
        

You can also take a look at the following article on how to manage folders using the Folders API. I hope this information helps.

If you filter images by their album id:

var images = librariesManager.GetImages().Where(i => i.Album.Id == albumId);

you will get all the images under the top level library, including the images from the nested libraries (folders).

I hope this information helps.

Regards,
Sabrie Nedzhip
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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 09-May-2014 00:00

Thanks a lot .Now will try to use it. Also have to sort the images under the folder.Let's see

This thread is closed