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

Adds a discussion forum to a given board. Accepts name, description, and other parameters. Category ID must be valid for the board ID. Returns numeric ID of new discussion forum as Long. 

See Also: The Example section.  

C#
public Long AddForum(Long BoardID, String Name, String Description, Boolean ModeratePosts, Boolean LockForum, int SortOrder, Long CategoryID);
Visual Basic
Public Function AddForum(ByVal BoardID As Long, ByVal Name As String, ByVal Description As String, ByVal ModeratePosts As Boolean, ByVal LockForum As Boolean, ByVal SortOrder As Integer, ByVal CategoryID As Long) As Long
Parameters 
Description 
BoardID 
The numeric ID of the board to which the forum will be added. 
Name 
The string name of the forum being added. 
Description 
String value for the forum summary. 
ModeratePosts 
Are posts moderated? 
LockForum 
Is the forum locked?
True - prevent posting to the forum. Only members of the Administrators user group can add, edit or delete posts.
False - the forum is unlocked. 
SortOrder 
Sort order for the new forum. For example, if you have multiple forums, you can assign an integer order to sort them. The order in which the forums appear, correspond to the numbers assigned to each one. 1 (one) is first on the list, 2 (two) appears second and so on. If you assign the same number to more than one forum, those forums are sorted in alphabetical order. 
CategoryID 
Numeric ID of the category to which the forum belongs. 

Numeric ID of new discussion forum. (Long)

The following example shows how to create a Web page from which a forum can be added to a discussion board. This example uses some standard drag and drop controls and a small section of VB code utilizing the AddForum method. This method uses the InternalAdmin to add the forum. 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. In the Web form, create a table with four rows and three columns.
  2. In the first row, first column, add the following label:
        <asp:Label ID="Label1" runat="server" Text="Board Id: "></asp:Label>
  3. In the first row, second column, add a text box to enter the board ID.
        <asp:TextBox ID="txtBoardId" runat="server" Width="63px"></asp:TextBox>
  4. In the first row, third column, add a RequiredFieldValidator control. This validates that something appears in the board ID box.
        <asp:RequiredFieldValidator ID="rfvBoardId" runat="server" ControlToValidate="txtBoardId"
             ErrorMessage="Please enter board ID"></asp:RequiredFieldValidator>
  5. In the second row, first column, add the following label:
        <asp:Label ID="Label4" runat="server" Text="Forum name: " Width="80px"></asp:Label>
  6. In the second row, second column, add a text box to enter the forum name.
        <asp:TextBox ID="txtForumName" runat="server" Width="254px"></asp:TextBox>
  7. In the second row, third column, add a RequiredFieldValidator control. This validates that something appears in the Forum Name box.
        <asp:RequiredFieldValidator ID="rfvForumName" runat="server" ErrorMessage="Please enter forum name"
               ControlToValidate="txtForumName"></asp:RequiredFieldValidator>
  8. In the third row, first column, add the following label:
        <asp:Label ID="Label7" runat="server" Text="Description:" Width="76px"></asp:Label>
  9. In the third row, second column, add a text box to enter a description.
        <asp:TextBox ID="txtDescription" runat="server" Width="253px"></asp:TextBox>
 10. In the third row, third column, add a RequiredFieldValidator control. This validates that something appears in the description box.
        <asp:RequiredFieldValidator ID="rfvDescription" runat="server" ErrorMessage="Please enter forum description" 
              ControlToValidate="txtDescription" Width="186px"></asp:RequiredFieldValidator>
 11. In the fourth row, first column, add the following label:
        <asp:Label ID="Label2" runat="server" Text="Category ID: " Width="76px"></asp:Label>
 12. In the fourth row, second column, add a text box to enter a Category ID.
        <asp:TextBox ID="txtCategoryId" runat="server" Width="75px"></asp:TextBox>
 13. In the fourth row, third column, add a RequiredFieldValidator control. This validates that something appears in the Category ID box.
        <asp:RequiredFieldValidator ID="rfvCatId" runat="server" ErrorMessage="Please enter category Id" 
              ControlToValidate="txtCategoryId"></asp:RequiredFieldValidator>
 14. After the table, add a couple of breaks for spacing purposes.
        <br /><br />
 15. Add a button, to submit the information.
        <asp:Button ID="btnAddForum" runat="server" Text="Add Forum" Width="72px" />
 16. Add a couple of more breaks for spacing purposes.
        <br /><br />
 17. Add a results label that will let the person using the page know whether or not the add succeeded.
        <asp:Label ID="lblResult" runat="server" Width="549px" Height="25px"></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 btnAddForum.Click

  1. Create objects for the following items.

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

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

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

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

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

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

           Try
               forumID = forumApi.AddForum(CInt(txtBoardId.Text), txtForumName.Text, txtDescription.Text, False, False, 1, CInt(txtCategoryId.Text))

  1. Add an If statement that displays a message stating if the forum was added and its ID.

               If (forumID <> 0) Then
                   lblResult.Text = "Forum added to the board with Forum ID = " & forumID
               End If

  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!