You are here: Ektron Namespace > .NET Assemblies > Ektron.Cms.API Namespace > Classes > Library Class > Library Methods > GetAllChildLibItems
Ektron CMS400.NET API Documentation
ContentsIndexHome
Example

The following example shows how to create a Web page that displays a graphical list of all images stored in the library for a specific folder in the Workarea. This example uses some standard drag and drop controls and a small section of VB code utilizing the GetAllChildLibItems method. This method uses the InternalAdmin to retrieve the images. In the first section, we will deal with the standard drag and drop controls. In the second, we'll deal with the code behind. 

 

  1. Between the form tags, add a Label with the following information.
       <asp:Label ID="Label6" runat="server" Text="Folder ID:" Width="76px"></asp:Label>
  2. Add a text box for the Folder ID.
       <asp:TextBox ID="txtFolderId" runat="server" Width="55px"></asp:TextBox>
  3. From the Validation control menu, add a RequiredFieldValidator control. This validates that something appears in the Folder ID box.
       <asp:RequiredFieldValidator ID="rfvId" runat="server" ControlToValidate="txtFolderId"
               ErrorMessage="Please enter a folder ID"></asp:RequiredFieldValidator>
  4. Add a couple of breaks for spacing purposes.
       <br /><br />
  5. Add a submit button. We will set the button click event in the code behind.
       <asp:Button ID="btnGet" runat="server" Text="Get Images" Width="74px" />
  6. Add two more breaks for spacing purposes.
       <br /><br />
  7. Add a label to display the list of images.
       <asp:Label ID="lblResult" runat="server"></asp:Label>

 

Add the following information to the code behind of your aspx.vb page.

  1. Add a button click event.

        Protected Sub btnGet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGet.Click

  1. Check to make sure the folder ID is numeric.

             If Not IsNumeric(txtFolderId.Text) Then
                 lblResult.Text = "Invalid Folder ID"
                 Exit Sub
             End If       

  1. Create an object for the library API.

             Dim libraryApi As New Ektron.Cms.API.Library

  1. Create an array to contain the library data.

             Dim data As Ektron.Cms.LibraryData()

  1. Create a Try/Catch around the GetAllChildLibItems method. This allows you to catch any exceptions and helps when debugging.

             Try
                 data = libraryApi.GetAllChildLibItems("images", CInt(txtFolderId.Text), "", 0, 0, 0)

  1. Check to make sure the library has images for the folder.

                 If (Not data Is Nothing) AndAlso (data.Length > 0) Then

  1. If so, create an object for each library item.

                     Dim item As Ektron.Cms.LibraryData

  1. Create an empty string.

                     Dim str As String = ""

  1. Iterate through each item and display the image with the image title as the alt text.

                      For Each item In data
                          str &= "<img src=""" & item.FileName & """ alt=""" & item.Title & """/>" & "<br/>" & "<br/>"
                          lblResult.Text = str
                      Next

  1. If the library contains no images for the folder, display a message.

                  Else
                      lblResult.Text = "No images found"
                  End If

  1. Display a message if there is an error.

             Catch ex As Exception
                 lblResult.Text = ex.Message
             End Try
    
     End Sub
Created with a commercial version of Doc-O-Matic. In order to make this message disappear you need to register this software. If you have problems registering this software please contact us at [email protected].
Copyright (c) 2008. All rights reserved.