---
title: Forums
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

## Forum groups

### Creating a forum group

```csharp

// Creates a new forum group object
ForumGroupInfo newGroup = new ForumGroupInfo();

// Sets the forum group properties
newGroup.GroupDisplayName = "New group";
newGroup.GroupName = "NewGroup";
newGroup.GroupSiteID = SiteContext.CurrentSiteID;
newGroup.GroupAuthorDelete = true;
newGroup.GroupAuthorEdit = true;
newGroup.GroupDisplayEmails = true;

// Saves the forum group to the database
ForumGroupInfoProvider.SetForumGroupInfo(newGroup);

```

[> Back to list of examples](#forums-toc)

### Updating a forum group

```csharp

// Gets the forum group
ForumGroupInfo updateGroup = ForumGroupInfoProvider.GetForumGroupInfo("NewGroup", SiteContext.CurrentSiteID);
if (updateGroup != null)
{
    // Updates the properties
    updateGroup.GroupDisplayName = updateGroup.GroupDisplayName.ToLower();

    // Saves the changes
    ForumGroupInfoProvider.SetForumGroupInfo(updateGroup);
}

```

[> Back to list of examples](#forums-toc)

### Updating multiple forum groups

```csharp

// Prepares parameters for loading all forum groups whose name starts with 'NewGroup'
string where = "GroupName LIKE N'NewGroup%'";
string orderBy = "";                

// Gets the forum groups based on the parameters
InfoDataSet<ForumGroupInfo> groups = ForumGroupInfoProvider.GetGroups(where, orderBy);

// Loops through individual groups
foreach (ForumGroupInfo forumGroup in groups)
{
    // Updates the properties
    forumGroup.GroupDisplayName = forumGroup.GroupDisplayName.ToUpper();

    // Saves the changes to the database
    ForumGroupInfoProvider.SetForumGroupInfo(forumGroup);
}

```

[> Back to list of examples](#forums-toc)

### Deleting a forum group

```csharp

// Gets the forum group
ForumGroupInfo deleteGroup = ForumGroupInfoProvider.GetForumGroupInfo("NewGroup", SiteContext.CurrentSiteID);

if (deleteGroup != null)
{
    // Deletes the forum group
    ForumGroupInfoProvider.DeleteForumGroupInfo(deleteGroup);
}

```

[> Back to list of examples](#forums-toc)

## Forums

### Creating a forum

```csharp

// Gets the parent forum group
ForumGroupInfo group = ForumGroupInfoProvider.GetForumGroupInfo("NewGroup", SiteContext.CurrentSiteID);

if (group != null)
{
    // Creates a new forum object
    ForumInfo newForum = new ForumInfo();

    // Sets the forum properties
    newForum.ForumDisplayName = "New forum";
    newForum.ForumName = "NewForum";
    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;

    // Saves the forum to the database
    ForumInfoProvider.SetForumInfo(newForum);
}

```

[> Back to list of examples](#forums-toc)

### Updating a forum

```csharp

// Gets the forum
ForumInfo updateForum = ForumInfoProvider.GetForumInfo("NewForum", SiteContext.CurrentSiteID);
if (updateForum != null)
{
    // Updates the properties
    updateForum.ForumDisplayName = updateForum.ForumDisplayName.ToLower();

    // Saves the changes to the database
    ForumInfoProvider.SetForumInfo(updateForum);
}

```

[> Back to list of examples](#forums-toc)

### Updating multiple forums

```csharp

// Prepares parameters for loading the first 10 forums whose name starts with 'NewForum'
string where = "ForumName LIKE N'NewForum%'";
string orderBy = "";
string columns = "";
int topN = 10;

// Gets the forums based on the parameters
InfoDataSet<ForumInfo> forums = ForumInfoProvider.GetForums(where, orderBy, topN, columns);

// Loops through individual forums
foreach (ForumInfo forum in forums)
{
    // Updates the properties
    forum.ForumDisplayName = forum.ForumDisplayName.ToUpper();

    // Saves the changes to the database
    ForumInfoProvider.SetForumInfo(forum);
}

```

[> Back to list of examples](#forums-toc)

### Deleting a forum

```csharp

// Gets the forum
ForumInfo deleteForum = ForumInfoProvider.GetForumInfo("NewForum", SiteContext.CurrentSiteID);

if (deleteForum != null)
{
    // Deletes the forum
    ForumInfoProvider.DeleteForumInfo(deleteForum);
}

```

[> Back to list of examples](#forums-toc)

## Forum posts

### Creating a forum post

```csharp

// Gets the forum
ForumInfo forum = ForumInfoProvider.GetForumInfo("NewForum", SiteContext.CurrentSiteID);
if (forum != null)
{
    // Creates a new forum post object
    ForumPostInfo newPost = new ForumPostInfo();

    // Sets the forum post properties
    newPost.PostUserID = MembershipContext.AuthenticatedUser.UserID;
    newPost.PostUserMail = MembershipContext.AuthenticatedUser.Email;
    newPost.PostUserName = MembershipContext.AuthenticatedUser.UserName;
    newPost.PostForumID = forum.ForumID;
    newPost.SiteId = forum.ForumSiteID;
    newPost.PostTime = DateTime.Now;
    newPost.PostApproved = true;
    newPost.PostSubject = "New post";
    newPost.PostText = "This is a new post";

    // Saves the forum post to the database
    ForumPostInfoProvider.SetForumPostInfo(newPost);
}

```

[> Back to list of examples](#forums-toc)

### Updating multiple forum posts

```csharp

// Prepares a condition for loading all forum posts whose subject starts with 'New post'
string where = "PostSubject LIKE N'New post%'";

// Gets the forum posts based on the condition
InfoDataSet<ForumPostInfo> posts = ForumPostInfoProvider.GetForumPosts(where);

// Loops through individual forum posts
foreach (ForumPostInfo forumPost in posts)
{
    // Updates the forum post properties
    forumPost.PostSubject = forumPost.PostSubject.ToUpper();

    // Saves the changes to the database
    ForumPostInfoProvider.SetForumPostInfo(forumPost);
}

```

[> Back to list of examples](#forums-toc)

### Deleting forum posts

```csharp

// Prepares a condition for loading all unapproved forum posts
string where = "PostApproved = 0";

// Gets all unapproved forum posts
InfoDataSet<ForumPostInfo> posts = ForumPostInfoProvider.GetForumPosts(where);

// Loops through individual forum posts
foreach (ForumPostInfo forumPost in posts)
{
    if (forumPost != null)
    {
        // Deletes the forum post
        ForumPostInfoProvider.DeleteForumPostInfo(forumPost);
    }
}

```

[> Back to list of examples](#forums-toc)
