You are here: Ektron Namespace > .NET Assemblies > Ektron.Cms.API Namespace > Ektron.Cms.API.Content Namespace > Classes > ThreadedDiscussion Class > ThreadedDiscussion Methods > GetForum
Ektron CMS400.NET API Documentation
ContentsIndexHome
PreviousUpNext
ThreadedDiscussion.GetForum Method

Method to obtain a particular forum by ID. Returns a discussion board with a 1 length Discussion Forum array. If the forum does not exist, then a DiscussionBoard with a zero length Forums property will be returned. 

See Also: The Example section.  

C#
public DiscussionBoard GetForum(Long forumid);
Visual Basic
Public Function GetForum(ByVal forumid As Long) As DiscussionBoard
Parameters 
Description 
forumid 
Numeric value of the forum ID. 

An instance of type DiscussionBoard.

The following example shows how to create a Web page from which forum data can be retrieved. This example uses some standard drag and drop controls and a small section of VB code utilizing the GetForum method. This method uses the InternalAdmin to retrieve the forum data. 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="Label1" runat="server" Text="Forum ID: "></asp:Label>
  2. Add a text box to enter the Forum ID.
        <asp:TextBox ID="txtForumId" runat="server" Width="63px"></asp:TextBox>
  3. From the Validation control menu, add a RequiredFieldValidator control. This validates that something appears in the Forum ID Box.
        <asp:RequiredFieldValidator ID="rfvForumId" runat="server" ControlToValidate="txtForumId"
              ErrorMessage="Please enter forum ID"></asp:RequiredFieldValidator>
  4. Add a couple of breaks for spacing purposes.
        <br /><br />
  5. Add a button, to retrieve the forum data.
        <asp:Button ID="btnGetForum" runat="server" Text="Get Forum" Width="72px" />
  6. Add a couple of more breaks for spacing purposes.
        <br /><br />
  7. Add a results label where the forum data will appear. This label is also used to display any errors that might occur.
        <asp:Label ID="lblResult" runat="server" Width="604px" Height="113px"></asp:Label>

 

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

  1. Add a button click event.

       Protected Sub btnGetForum_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetForum.Click

  1. Create objects for the following items.

           Dim board As New Ektron.Cms.DiscussionBoard
           Dim forumApi As New Ektron.Cms.API.Content.ThreadedDiscussion

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

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

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

           Try
               board = forumApi.GetForum(CInt(txtForumId.Text))

  1. Check to make sure the discussion board and forum are valid.

               If (board.Id = 0) Or (board.Forums.Length <> 1) Then
                   lblResult.Text = "Error getting forum"
                   Exit Sub
               End If

  1. Display the Discussion Board data.

               lblResult.Text = "Board Title: " & board.Title & "<br/>"
               lblResult.Text &= "Board Name: " & board.Name & "<br/>"

  1. Display the Forum data.

               lblResult.Text &= "Forum Category: " & board.Forums(0).CategoryName & "<br/>"
               lblResult.Text &= "Forum Name: " & board.Forums(0).ForumName & "<br/>"
               lblResult.Text &= "Forum Title: " & board.Forums(0).ForumTitle & "<br/>"
               lblResult.Text &= "Number of topics: " & board.Forums(0).NumberofTopics & "<br/>"
               lblResult.Text &= "Number of posts: " & board.Forums(0).NumberofPosts & "<br/>"

  1. If there is an error, let the user know what happened.

           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.
What do you think about this topic? Send feedback!