You are here: Ektron Namespace > .NET Assemblies > Ektron.Cms.API Namespace > Classes > Folder Class > Folder Methods > GetChildFolders Method > GetChildFolders
Ektron CMS400.NET API Documentation
ContentsIndexHome
PreviousUpNext
Folder.GetChildFolders Method (Long, Boolean, EkEnumeration.FolderOrderBy)

Loads all the subfolders for a given folder ID.  

See Also: The Example section.  

C#
public FolderData[] GetChildFolders(Long id, Boolean recursive, EkEnumeration.FolderOrderBy orderBy);
Visual Basic
Public Function GetChildFolders(ByVal id As Long, ByVal recursive As Boolean, ByVal orderBy As EkEnumeration.FolderOrderBy) As FolderData()
Parameters 
Description 
id 
The folder's ID 
recursive 
True = recursive look up. False = none. 
orderBy 
Field to order results by. 

Ektron.Cms.FolderData()

The following example shows how to create a Web page from which a folder ID can be entered and list of child folders returned. This example uses some standard drag and drop controls and a small section of VB code utilizing the GetChildFolders method. This method uses the InternalAdmin to retrieve the child folder list. 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 the following label:
       <asp:Label ID="Label1" runat="server" Text="Folder ID: "></asp:Label>
  2. Add a text box to enter the folder's ID.
       <asp:TextBox ID="txtFolderId" runat="server" Width="44px"></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="rfvFolderId" runat="server" ControlToValidate="txtFolderId"
           ErrorMessage="Please enter 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="btnGetChildFolders" runat="server" Text="Get Child Folders" Width="123px" />
  6. Add two more breaks for spacing purposes.
       <br /><br />
  7. Add a label to display the list of child folder names.
       <asp:Label ID="lblResult" runat="server" Width="272px"></asp:Label>

 

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

  1. Add a button click event.

        Protected Sub btnGetChildFolders_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetChildFolders.Click

  1. Create an object for the Folder API.

             Dim folderApi As New Ektron.Cms.API.Folder

  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 as an array of FolderData.

             Dim folders As Ektron.Cms.FolderData()

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

             Try
                 folders = folderApi.GetChildFolders(CInt(txtFolderId.Text), True, FolderOrderBy.Name)

  1. Use an If/Else statement to display whether child folders exist.

                 If (folders Is Nothing) Then
                     lblResult.Text &= "Child folders: None"

  1. If child folders exist, display a total count.

                 Else
                     lblResult.Text &= "Child folders: " & folders.Length.ToString & "<br/>"

  1. Iterate through the array and display each child folder's name.

                     Dim i As Integer
                     For i = 0 To folders.Length - 1 Step 1
                         lblResult.Text &= folders(i).Name & "<br/>"
                     Next
                 End If

  1. Display a message if there is an error.

              Catch ex As Exception
                 lblResult.Text = "Error getting child folders"
              End Try
    
     End Sub

  1. Add a page load event so that lblResult.Text is blank when the page first loads.

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      lblResult.Text = ""
   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.
What do you think about this topic? Send feedback!