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

Forums / Developing with Sitefinity / Get All iamges of the current libarary

Get All iamges of the current libarary

5 posts, 0 answered
  1. kamii47
    kamii47 avatar
    71 posts
    Registered:
    02 Mar 2007
    06 May 2014
    Link to this post
    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();                

                }

  2. readonlychild
    readonlychild avatar
    67 posts
    Registered:
    26 May 2011
    07 May 2014
    Link to this post

    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;
    }

     

  3. kamii47
    kamii47 avatar
    71 posts
    Registered:
    02 Mar 2007
    07 May 2014 in reply to readonlychild
    Link to this post

    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.

  4. Sabrie Nedzhip
    Sabrie Nedzhip avatar
    534 posts
    Registered:
    02 Dec 2016
    09 May 2014
    Link to this post
    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
     
  5. kamii47
    kamii47 avatar
    71 posts
    Registered:
    02 Mar 2007
    09 May 2014 in reply to Sabrie Nedzhip
    Link to this post

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

5 posts, 0 answered