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.
Protected Sub btnGet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGet.Click
If Not IsNumeric(txtFolderId.Text) Then lblResult.Text = "Invalid Folder ID" Exit Sub End If
Dim libraryApi As New Ektron.Cms.API.Library
Dim data As Ektron.Cms.LibraryData()
Try data = libraryApi.GetAllChildLibItems("images", CInt(txtFolderId.Text), "", 0, 0, 0)
If (Not data Is Nothing) AndAlso (data.Length > 0) Then
Dim item As Ektron.Cms.LibraryData
Dim str As String = ""
For Each item In data str &= "<img src=""" & item.FileName & """ alt=""" & item.Title & """/>" & "<br/>" & "<br/>" lblResult.Text = str Next
Else lblResult.Text = "No images found" End If
Catch ex As Exception lblResult.Text = ex.Message End Try End Sub