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

Forums / Developing with Sitefinity / sort Library images

sort Library images

2 posts, 0 answered
  1. Priya Ramesh
    Priya Ramesh avatar
    26 posts
    Registered:
    23 Jul 2009
    29 Sep 2009
    Link to this post

    Hi ,
      I am gettiing all the images from the library named "Media-Images".Is there a way to sort the images by name or type in the code below.

     

    LibraryManager

    lMan = new LibraryManager("Libraries");

     

     

    ILibrary

    ilib = lMan.GetLibrary("Media-Images");

     

     

    if (ilib != null)

     

    {

     

    IList medialist = ilib.GetItems();

     

     

    //bind to repeater
    rpLibrary.DataSource = medialist;

    rpLibrary.DataBind();

    }

    Thanks,
    Priya

  2. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    01 Jun 2017
    30 Sep 2009
    Link to this post
    Hi Priya Ramesh,

    Here is a simple code that sorts the images by Name metafield, you can change your code accordingly:

     protected void Page_Load(object sender, EventArgs e) 
        { 
            var libraryManager = new LibraryManager();         
            var library = libraryManager.GetLibrary("sameName");         
            var items = library.GetItems(); 
             
            var sortedList = new List<IContent>(); 
            foreach(IContent item in items) 
                sortedList.Add(item);         
             
            sortedList.Sort(new Comparison<IContent>(this.ToCompare));            
        } 
         
        private int ToCompare(IContent x, IContent y)    
        { 
            var xName = x.GetMetaData("Name").ToString(); 
            var yName = y.GetMetaData("Name").ToString(); 
             
            return xName.CompareTo(yName); 
        } 

    Hope this helps.

    Regards,
    Nikolai
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered