Creating threads

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

The following sample code shows how you can create a new thread and add it to a forum:

 

[C#]

 

using System;

using CMS.Forums;

using CMS.CMSHelper;

 

...

 

        // Get forum object

        ForumInfo fi = ForumInfoProvider.GetForumInfo("CustomForum"CMSContext.CurrentSiteID);

 

        // If forum exists

        if (fi != null)

        {

            // Create new thread object

            ForumPostInfo fpi = new ForumPostInfo();

 

            // Set properties

            fpi.PostUserID = CMSContext.CurrentUser.UserID;

            fpi.PostUserMail = CMSContext.CurrentUser.Email;

            fpi.PostUserName = CMSContext.CurrentUser.UserName;

            fpi.PostForumID = fi.ForumID;

            fpi.PostTime = DateTime.Now;

            fpi.PostApproved = true;

            fpi.PostText = "This is a forum post";

            fpi.PostSubject = "Post subject";

 

            // Save thread to database

            ForumPostInfoProvider.SetForumPostInfo(fpi);

 

        }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_creating_threads.htm