There are several ways in which you can find one or more forums:
Let’s examine the examples for each of the ways to find one or more forums:
Get forum with specific ID:
| GetForum(Guid forumID) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // Since we don't know ID of any of the forums we'll
get all of them and use the first one
// to retrieve a specific forum.
// The GetForums(bool excludeHidden) method returns an object of type IList<IForum>,
// so we create a list of all forums
IList listOfForums = forumManager.GetForums(false); if (listOfForums.Count > 0)
{
// get the first forum
Telerik.Forums.IForum firstForum = (Telerik.Forums.IForum)listOfForums[0];
// get the ID of the first forum which we will use to retrieve the forum
// (this is a redundant step since we already have the forum, but is used here to
// demonstrate the approach)
Guid forumId = firstForum.ID;
Telerik.Forums.IForum theForum = forumManager.GetForum(forumId);
// write the list name to see the result
Response.Write(theForum.Name);
}
|
Get all forums in the Forums module (with option to exculde hidden ones):
| GetForums(bool excludeHidden) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // The GetForums(bool excludeHidden) method returns an
object of type IList,
// so we create a list of all forums (including hidden ones) IList listOfForums =
forumManager.GetForums(false); foreach (Telerik.Forums.IForum forum in listOfForums)
{
Response.Write(forum.Name + "<br />");
}
|
Get specific subset of all forums that belong to given category (with option to exculde hidden ones):
| GetForums(ICategory category, bool excludeHidden) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get all categories IList listOfAllCategories = forumManager.GetCategories(); if (listOfAllCategories.Count
> 0)
{
// get first category
Telerik.Forums.ICategory firstCategory = (Telerik.Forums.ICategory)listOfAllCategories[0];
// The GetForums(ICategory category, bool excludeHidden) method returns an object of type IList,
// so we create a list of all forums
IList listOfForums = forumManager.GetForums(firstCategory, false);
if (listOfForums.Count > 0)
{
foreach (Telerik.Forums.IForum forum in listOfForums)
{
Response.Write(forum.Name + "<br
/>");
}
}
else
Response.Write("There are no forums in this
category!");
} else
Response.Write("There are no categories!");
|
Get specific subset of all forums that belong to given category with specified ID (with option to exculde hidden ones):
| GetForums(Guid categoryID, bool excludeHidden) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get all categories IList listOfAllCategories = forumManager.GetCategories(); if (listOfAllCategories.Count
> 0)
{
// get first category
Telerik.Forums.ICategory firstCategory = (Telerik.Forums.ICategory)listOfAllCategories[0];
// get category ID
Guid firstCategoryId = firstCategory.ID;
// The GetForums(ICategory category, bool excludeHidden) method returns an object of type IList,
// so we create a list of all forums
IList listOfForums = forumManager.GetForums(firstCategoryId, false);
if (listOfForums.Count > 0)
{
foreach (Telerik.Forums.IForum forum in listOfForums)
{
Response.Write(forum.Name + "<br
/>");
}
}
}
|
Get specific subset of all forums with specified IDs (with option to exculde hidden ones):
An example of when this method could be used is RSS for forums. Only selected forums are passed to the service and so their IDs will be needed. The following example gets
the forums of a specific category and then gets their IDs. Then, these IDs are passed to the GetForums method - this is a redundant step but it serves the purpose of
demonstrating how to use the method:
| GetForums(Guid[] ids, bool excludeHidden) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get all categories IList listOfAllCategories = forumManager.GetCategories(); if (listOfAllCategories.Count
> 0)
{
// get first category
Telerik.Forums.ICategory firstCategory = (Telerik.Forums.ICategory)listOfAllCategories[0];
// The GetForums(ICategory category, bool excludeHidden) method returns an object of type IList,
// so we create a list of all forums
IList listOfForums = forumManager.GetForums(firstCategory, false);
if (listOfForums.Count > 0)
{
Telerik.Forums.IForum firstForum = (Telerik.Forums.IForum)listOfForums[0];
Guid firstForumId = firstForum.ID;
Telerik.Forums.IForum secondForum = (Telerik.Forums.IForum)listOfForums[1];
Guid secondForumId = secondForum.ID;
Guid[] selectedForums = new Guid[10];
selectedForums[0] = firstForumId;
selectedForums[1] = secondForumId;
IList listOfSelectedForums = forumManager.GetForums(selectedForums, false);
if (listOfSelectedForums.Count > 0)
{
foreach (Telerik.Forums.IForum
forum in listOfSelectedForums)
{
Response.Write(forum.Name + "<br
/>");
}
}
}
}
|
Get all forums in the Forums module which do not belong to any category (with option to exculde hidden ones):
| GetForumsUncategorized(bool excludeHidden) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // The GetForumsUncategorized(bool excludeHidden)
method returns an object of type IList,
// so we create a list of all forums IList listOfForums =
forumManager.GetForumsUncategorized(false); foreach (Telerik.Forums.IForum forum
in listOfForums)
{
Response.Write(forum.Name + "<br />");
}
|
Get recent forums with specified numbers - which forum to start with and how many to get:
| GetRecentForumns(int start, int max) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // The GetRecentForumns(int start, int max)method
returns an object of type IList,
// so we create a list of all forums. The parameters are the following:
// '0' - Start from the most recent forum (the one created last)
// '3' - Get no more than three forums IList listOfForums = forumManager.GetRecentForumns(0, 3); foreach (Telerik.Forums.IForum forum in listOfForums)
{
Response.Write(forum.Name + "<br />");
}
|
See Also