Sitefinity CMS

Finding Forum Categories Send comments on this topic.
See Also
Developing with Sitefinity > Modules > Modules API > Forums > Forum Categories > Finding Forum Categories

Glossary Item Box

There are several ways to retrieve one or more forum categories. Choose an appropriate function given the particular scenario:

Get a specific Category by its ID:

GetCategory(Guid categoryID) Copy Code
// create new instance of ForumManager
Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager();
// get all categories. This is redundant - added for demonstration
IList listOfAllCategories = forumManager.GetCategories();
if (listOfAllCategories.Count > 0)
{
   
// get ID of first category. This is redundant - added for demonstration
   
Telerik.Forums.ICategory firstCategory = (Telerik.Forums.ICategory)listOfAllCategories[0];
   Guid firstCategoryId = firstCategory.ID;
  
   
// get a category with specified ID
   
Telerik.Forums.ICategory theCategory = forumManager.GetCategory(firstCategoryId);
   Response.Write(theCategory.Name +
"<br />");
}

 

Get all Categories:

GetCategories() 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)
{
   
foreach (Telerik.Forums.ICategory categ in listOfAllCategories)
       Response.Write(categ.Name +
"<br />");
}

 

Get all Categories ordered by sort expression:

GetCategories(string sortExpr) Copy Code
// create new instance of ForumManager
Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager();
// get all categories sorted by an expression
IList listOfAllCategories = forumManager.GetCategories("Name ASC");
if (listOfAllCategories.Count > 0)
{
   
foreach (Telerik.Forums.ICategory categ in listOfAllCategories)
       Response.Write(categ.Name +
"<br />");
}

 

Get a specific set of Categories by their IDs:

GetCategoriesByIds(params Guid[] ids) Copy Code
// create new instance of ForumManager
Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager();
// get all categories. This is redundant - added for demonstration
IList listOfAllCategories = forumManager.GetCategories();
// get IDs of the first two categories. This is redundant - added for demonstration
Guid firstCategoryId = ((Telerik.Forums.ICategory)listOfAllCategories[0]).ID;
Guid secondCategoryId = ((Telerik.Forums.ICategory)listOfAllCategories[1]).ID;
// create an array of Guid and save the IDs of the two categories in it
Guid[] arrayOfCategoryIDs = new Guid[10];
arrayOfCategoryIDs
[0] = firstCategoryId;
arrayOfCategoryIDs
[1] = secondCategoryId;
// get all categories with the specified IDs
IList listOfSpecifiedCategories = forumManager.GetCategoriesByIds(arrayOfCategoryIDs);
if (listOfSpecifiedCategories.Count > 0)
{
   
foreach (Telerik.Forums.ICategory categ in listOfSpecifiedCategories)
       Response.Write(categ.Name +
"<br />");
}

 

 

See Also