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

Forums / Developing with Sitefinity / How do I get only the image library list to appear on a page?

How do I get only the image library list to appear on a page?

5 posts, 0 answered
  1. Karl
    Karl avatar
    1 posts
    Registered:
    15 Jun 2009
    15 Jun 2009
    Link to this post
    I have set up numerous image libraries on our clbs website. However the page which has the image libraries selected to show displays all images and not just a list of the libraries. Ideally I want the libraries to be listed with a name and the first image showing.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    15 Jun 2009
    Link to this post
    Hi Karl,

    You should create a custom user control. For instance you can create a repeater. There are two controls - Image and Label. The label will show the ILibrary name and the Image will show the fist or random image.

    Here is a sample code that you can extend.

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="CustomImageGallery.ascx.cs" Inherits="CustomControls_CustomImageGallery" %> 
     
    <asp:Repeater ID="repeater1" runat="server" OnItemDataBound="Repeater_ItemDataBound" > 
    <HeaderTemplate> 
    </HeaderTemplate> 
    <ItemTemplate> 
    <asp:Image ID="image1" runat="server" /> 
    <asp:Label ID="label1" runat="server" Text="Gallery Title"></asp:Label> 
    </ItemTemplate> 
    </asp:Repeater> 


    public partial class CustomControls_CustomImageGallery : System.Web.UI.UserControl 
       // create instance of LibraryManager 
        private LibraryManager manager; 
        public LibraryManager Manager 
        { 
            get 
            { 
                if (this.manager == null
                    this.manager = new LibraryManager(); 
                return this.manager; 
            } 
        } 
     
        protected void Page_Load(object sender, EventArgs e) 
        { 
            //get all libraries 
            this.repeater1.DataSource = this.Manager.GetAllLibraries(); 
            this.repeater1.DataBind(); 
        } 
     
        public void Repeater_ItemDataBound(Object Sender, RepeaterItemEventArgs e) 
        { 
            // find the controls, set the image you want to see 
            // set the text of the label control to the Library Name 
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
            { 
                Label lbl = (Label)e.Item.FindControl("label1"); 
                Image img = (Image)e.Item.FindControl("image1"); 
     
                ILibrary mygallery = ((ILibrary)e.Item.DataItem); 
                lbl.Text = mygallery.Name; 
                IList content = this.Manager.GetChildItems(mygallery.ID); 
                Random random = new Random(); 
                IContent randomImage = (IContent)content[random.Next(0, content.Count - 1)]; 
                img.ImageUrl = randomImage.ThumbnailUrl; 
            } 
        } 
     
     


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Eddie
    Eddie avatar
    2 posts
    Registered:
    17 Nov 2008
    22 Sep 2009
    Link to this post
    Guys,
        I have been trying to get this working but the link I get for the  "img.ImageUrl = randomImage.ThumbnailUrl;" is Libraries/Photo_Gallery/Group_Event_Paris.sflb.ashx, which is turning up a broken image?  Tries the various linkparser.resolve etc.. but not having much luck.
        Regards,
            Eddie
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    22 Sep 2009
    Link to this post
    Hello Eddie,

    If you have not changed the value of urlRewriteFormat in your web.config the url should be resolved correctly( Example: ~/Libraries/SecondLibrary/beaches-108_2.tmb.ashx). The code is working under 3.7 as well.

    Best wishes,
    Ivan Dimitrov
    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.
  5. Eddie
    Eddie avatar
    2 posts
    Registered:
    17 Nov 2008
    22 Sep 2009
    Link to this post
    Thanks Ivan, figured out what the problem is, the url's either don't like a port or running from a debugger, they images were not appearing when running under http://localhost:50155/etc....
    Thanks again for your quick reply
Register for webinar
5 posts, 0 answered