There are several ways to retrieve one or more forum posts. Choose an appropriate function given the particular scenario:
Get a specific post by its ID:
| GetPost(Guid postID) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get all forums IList listOfForums = forumManager.GetForums(false); if (listOfForums.Count > 0)
{
// get first forum
Telerik.Forums.IForum firstForum = (Telerik.Forums.IForum)listOfForums[0];
// get all threads (root posts)
IList listOfThreads = forumManager.GetForumThreads(firstForum, false);
if (listOfThreads.Count > 0)
{
//get first thread - this step is redundant but is used for demonstration
Telerik.Forums.IPost rootPost = (Telerik.Forums.IPost)listOfThreads[0];
//get ID
Guid rootPostId = rootPost.ID;
// get the post
Telerik.Forums.IPost thePost = forumManager.GetPost(rootPostId);
Response.Write(thePost.Title + "<br />");
}
}
|
Get posts by specifying their parent post:
| GetPosts(IPost parent) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get all forums IList listOfForums = forumManager.GetForums(false); if (listOfForums.Count > 0)
{
// get first forum
Telerik.Forums.IForum firstForum = (Telerik.Forums.IForum)listOfForums[0];
// get all threads (root posts)
IList listOfThreads = forumManager.GetForumThreads(firstForum, false);
if (listOfThreads.Count > 0)
{
//get first thread
Telerik.Forums.IPost rootPost = (Telerik.Forums.IPost)listOfThreads[0];
// get the list of all posts
IList listOfPosts = forumManager.GetPosts(rootPost);
if (listOfPosts.Count > 0)
{
foreach (Telerik.Forums.IPost
postItem in listOfPosts)
Response.Write(postItem.Content + "<br />");
}
}
}
|
Get posts by specifying their parent post ID, and whether they should be ordered descendingly (true), and whether they should be
only Visible (and not Hidden or Locked - true):
| GetPosts(Guid parentID, bool descending, bool visibleOnly) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get all forums IList listOfForums = forumManager.GetForums(false); if (listOfForums.Count > 0)
{
// get first forum
Telerik.Forums.IForum firstForum = (Telerik.Forums.IForum)listOfForums[0];
// get all threads (root posts)
IList listOfThreads = forumManager.GetForumThreads(firstForum, false);
if (listOfThreads.Count > 0)
{
//get first thread
Telerik.Forums.IPost rootPost = (Telerik.Forums.IPost)listOfThreads[0];
Guid rootPostId = rootPost.ID;
// get the list of all posts,ascending order
IList listOfPosts = forumManager.GetPosts(rootPostId, false, false);
if (listOfPosts.Count > 0)
{
foreach (Telerik.Forums.IPost
postItem in listOfPosts)
Response.Write(postItem.Content + "<br />");
}
}
}
|
Get all posts for a given author:
| GetPostsByAuthor(string authorName) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get the list of all posts for a given
author IList listOfPosts = forumManager.GetPostsByAuthor("Author Name"); if (listOfPosts.Count > 0)
{
foreach (Telerik.Forums.IPost postItem in
listOfPosts)
Response.Write(postItem.Content + "<br />");
}
|
Get all posts of a given forum object:
| GetForumPosts(IForum parentForum) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get all forums IList listOfForums = forumManager.GetForums(false); if (listOfForums.Count > 0)
{
// get first forum
Telerik.Forums.IForum firstForum = (Telerik.Forums.IForum)listOfForums[0];
// get all posts for this forum
IList listOfPosts = forumManager.GetForumPosts(firstForum);
if (listOfPosts.Count > 0)
{
foreach (Telerik.Forums.IPost postItem in listOfPosts)
Response.Write(postItem.Content + "<br
/>");
}
}
|
Get all posts of a given forum object ID:
| GetForumPosts(Guid parentForumID) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get all forums IList listOfForums = forumManager.GetForums(false); if (listOfForums.Count > 0)
{
// get first forum
Telerik.Forums.IForum firstForum = (Telerik.Forums.IForum)listOfForums[0];
Guid firstForumId = firstForum.ID;
// get all posts for this forum with specified ID
IList listOfPosts = forumManager.GetForumPosts(firstForumId);
if (listOfPosts.Count > 0)
{
foreach (Telerik.Forums.IPost postItem in listOfPosts)
Response.Write(postItem.Content + "<br
/>");
}
}
|
Get all root posts of a given forum object ID (with option to exclude hidden):
| GetForumThreads(Guid parentForumID, bool excludeHidden) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get all forums IList listOfForums = forumManager.GetForums(false); if (listOfForums.Count > 0)
{
// get first forum
Telerik.Forums.IForum firstForum = (Telerik.Forums.IForum)listOfForums[0];
Guid firstForumId = firstForum.ID;
// get all posts for this forum with specified ID
IList listOfPosts = forumManager.GetForumThreads(firstForumId,false);
if (listOfPosts.Count > 0)
{
foreach (Telerik.Forums.IPost postItem in listOfPosts)
Response.Write(postItem.Content + "<br
/>");
}
}
|
Get all root posts of a given forum object (with option to exclude hidden):
| GetForumThreads(IForum parentForum, bool excludeHidden) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // get all forums IList listOfForums = forumManager.GetForums(false); if (listOfForums.Count > 0)
{
// get first forum
Telerik.Forums.IForum firstForum = (Telerik.Forums.IForum)listOfForums[0];
// get all posts for this forum with specified ID
IList listOfPosts = forumManager.GetForumThreads(firstForum, false);
if (listOfPosts.Count > 0)
{
foreach (Telerik.Forums.IPost postItem in listOfPosts)
Response.Write(postItem.Content + "<br
/>");
}
}
|
Get the recent posts starting from given post (start) and getting given number of posts (max):
The max parameter denotes the number of posts returned. Have in mind that in a single forum thread, a post is considered each reply to the root post (the
so-called thread). This means that if there are two replies to the root thread, and each of them has five replies, this method will return the two replies to the root thread as
well as the other ten posts (and not only a total of three posts).
| GetRecentPosts(int start, int max) |
Copy Code |
|
// create new instance of ForumManager Telerik.Forums.ForumManager forumManager = new Telerik.Forums.ForumManager(); // list of recent posts starting from the most recent
one ('0')
// and retreiving only up to three posts ('3') IList listOfRecentPosts = forumManager.GetRecentPosts(0,
3); if (listOfRecentPosts.Count > 0)
{
foreach (Telerik.Forums.IPost postItem in
listOfRecentPosts)
Response.Write(postItem.Content + "<br />");
}
|
See Also