Displaying Library Images Using Framework API and .Net Server Control

  • Updated

The following code sample show how to input a library image ID and display the corresponding image on the template. The image displays in a .Net server control that permits added development functionality. 

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void uxSubmit_Click(Object sender, EventArgs e)
        long LibraryID = long.Parse(uxLibraryId.Text);
        Ektron.Cms.Framework.Content.LibraryManager lM = new Ektron.Cms.Framework.Content.LibraryManager(Ektron.Cms.Framework.ApiAccessMode.Admin);
        Ektron.Cms.LibraryData lD = new Ektron.Cms.LibraryData();
        //retrieves the library item and assigns it to the library data object
        lD = lM.GetItem(LibraryID);
        //sets the asp image control visible to true
        image.Visible = true;
        //fills in the controls image url with the path returned from the content asset data object image path  
        image.ImageUrl = lD.FileName;
        uxSubmit.Visible = false;
        uxLibraryId.Visible = false;
        uxLibraryIdLabel.Visible = false;

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
      <form id="form1" runat="server">
            <ektronUI:Label ID="uxLibraryIdLabel" AssociatedControlID="uxLibraryId" CssClass="span-6 last" runat="server" Text="Library Id :" />
            <ektronUI:TextField ID="uxLibraryId" CssClass="span-6" runat="server" ValidationGroup="RegisterValidationGroup" />
            <ektronUI:Button id="uxSubmit" runat="server" OnClick="uxSubmit_Click" Text="Get Item"></ektronUI:Button>
           <asp:Image runat="server" AlternateText="your image" ID="image" Visible="false" />