Kentico CMS 6.0 Developer's Guide

Managing forums

Managing forums

Previous topic Next topic Mail us feedback on this topic!  

Managing forums

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a forum.

 

private bool CreateForum()
{

  // Get the forum group
  ForumGroupInfo group = ForumGroupInfoProvider.GetForumGroupInfo("MyNewGroup", CMSContext.CurrentSiteID);

 
    if (group != null)
    {
        // Create new forum object
        ForumInfo newForum = new ForumInfo();
 
        // Set the properties
        newForum.ForumDisplayName = "My new forum";
        newForum.ForumName = "MyNewForum";
        newForum.ForumGroupID = group.GroupID;
        newForum.ForumSiteID = group.GroupSiteID;
        newForum.AllowAccess = SecurityAccessEnum.AllUsers;
        newForum.AllowAttachFiles = SecurityAccessEnum.AuthenticatedUsers;
        newForum.AllowPost = SecurityAccessEnum.AllUsers;
        newForum.AllowReply = SecurityAccessEnum.AllUsers;
        newForum.AllowSubscribe = SecurityAccessEnum.AllUsers;
        newForum.ForumOpen = true;
        newForum.ForumModerated = false;
        newForum.ForumThreads = 0;
        newForum.ForumPosts = 0;
 
        // Save the forum
        ForumInfoProvider.SetForumInfo(newForum);
 
        return true;
    }
 
    return false;
}

 

The following example gets and updates a forum.

 

private bool GetAndUpdateForum()
{

  // Get the forum
  ForumInfo updateForum = ForumInfoProvider.GetForumInfo("MyNewForum", CMSContext.CurrentSiteID);

    if (updateForum != null)
    {
        // Update the properties
        updateForum.ForumDisplayName = updateForum.ForumDisplayName.ToLower();
 
        // Save the changes
        ForumInfoProvider.SetForumInfo(updateForum);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates forums.

 

private bool GetAndBulkUpdateForums()
{
    // Prepare the parameters
    string where = "ForumName LIKE N'MyNewForum%'";
    string orderBy = "";
    string columns = "";
    int topN = 10;
 
    // Get the data
    DataSet forums = ForumInfoProvider.GetForums(where, orderBy, topN, columns);
    if (!DataHelper.DataSourceIsEmpty(forums))
    {
        // Loop through the individual items
        foreach (DataRow forumDr in forums.Tables[0].Rows)
        {
            // Create object from DataRow
            ForumInfo modifyForum = new ForumInfo(forumDr);
 
            // Update the properties
            modifyForum.ForumDisplayName = modifyForum.ForumDisplayName.ToUpper();
 
            // Save the changes
            ForumInfoProvider.SetForumInfo(modifyForum);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a forum.

 

private bool DeleteForum()
{

  // Get the forum
  ForumInfo deleteForum = ForumInfoProvider.GetForumInfo("MyNewForum", CMSContext.CurrentSiteID);

 
    // Delete the forum
    ForumInfoProvider.DeleteForumInfo(deleteForum);
 
    return (deleteForum != null);
}