Search code examples
asp.netsitecoresitecore7.2

Sitecore Images in Media Library in a Folder are not shown on front end


Its the first time I am working with Media Items.

I have some images in Media Items,

/sitecore/media library/Files/News/Images/

In the content editor I have seen there are 3 images. I just want to display the images which are in the above folder (which are child of above item)

I am using following code:

Asp.Net:

<asp:Label runat="server" ID="lblTest"></asp:Label>
<br/>
<asp:Repeater runat="server" ID="repImages">
    <ItemTemplate>
        <asp:Image ID="Image1" ImageUrl='<%# LinkManager.GetItemUrl(Container.DataItem as Item)  %>' runat="server" Height="100" Width="100" />
        <asp:Label runat="server" Text="<%# GeneralHelper.GetItemField(Container.DataItem as Item)  %>"></asp:Label>
    </ItemTemplate>
</asp:Repeater>

Code Behind:

Item mediaItem = Sitecore.Context.Database.GetItem("/sitecore/media library/Files/News/Images");

lblTest.Text = "Total Images: "+mediaItem.Children.Count.ToString();

repImages.DataSource = mediaItem.Children;
repImages.DataBind();

OutPut:

enter image description here


Solution

  • Since this is a media item you are trying to resolve the URL for, I believe you need to use the MediaManager instead of the LinkManager.

    Sitecore.Resources.Media.MediaManager.GetMediaUrl(item);
    

    More details at: https://briancaos.wordpress.com/2012/08/24/sitecore-links-with-linkmanager-and-mediamanager/