Search code examples
c#teleriksitefinitysitefinity-5

Getting an Image from Telerik Sitefinity Modules


I'm using Telerik Sitefinity 5.1. I've build a module that has 3 fields {title, url, image} title and url -> string field image -> 'image selector'

.cs

protected void Page_Load(object sender, EventArgs e)
    {       
        var myCollection = GetDataItems();

        RadRotator1.DataSource = myCollection;
        RadRotator1.DataBind();
    }

    public IQueryable<DynamicContent> GetDataItems()
    {
        DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
        Type brandLogosType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.BrandLogos.BrandLogos");         
        var myCollection = dynamicModuleManager.GetDataItems(brandLogosType).Where(i => i.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live && i.Visible == true);

        return myCollection;
    }

asp.x

<telerik:RadRotator ID="RadRotator1" runat="server" RotatorType="AutomaticAdvance"
BorderWidth="4px" Width="100px" Height="100px" ScrollDirection="Down">
<ItemTemplate>
    <asp:Image runat="server" ID="image1" />
    <%-- <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("title") %>'></asp:Label>--%>
    <asp:Image ID="img1" runat="server" ImageUrl='<%# Eval("UrlWithExtension") %>' />
</ItemTemplate>

Getting title and url field with Text='<%# Eval("title") %>' But don't know how to get image like this. Can somebody show me?

Thanks in advance.


Solution

  • the Image field stores a reference to a Sitefinity image using a ContentLink, this ContentLink is what is actually stored in the property.

    You can expand the content link to get the image with a helper method, as described here: http://www.sitefinity.com/blogs/joshmorales/posts/josh-morales-blog/2012/01/19/retrieving_data_from_dynamic_modules_using_the_module_builder_api

    I hope this is helpful!