Got more questions? Find advice on: ASP | SQL | XML | Regular Expressions
in Search
Welcome to WindowsAdvice Sign in | Join | Help

Christian Nordbakk

Some of this, and some of that...

Latest Forums Posts UserControl in CommunityServer

One of the things we wanted for WindowsAdvice was for the 10 most recent forum posts to be displayed on the frontpage. CommunityServer doesn’t provide a finished control for this, but does already have the functionality. Here’s a quick post to explain how to find and use this functionality on your own site. I’ve also provided a download to a very basic, but functional UserControl for demonstration.

In the CommunityServer.Discussions assembly, under the CommunityServer.Discussions.Components namespace there is nifty little class named Threads. This class contains a GetThreads method which, when called will return a set of threads that match the criteria’s you supply as parameters.

I won’t go into much detail on the parameters beyond the method signature which I’ve copied out of Reflector:

public static ThreadSet GetThreads(int forumID, int pageIndex, int pageSize, User user, DateTime threadsNewerThan, SortThreadsBy sortBy, SortOrder sortOrder, ThreadStatus threadStatus, ThreadUsersFilter userFilter, bool activeTopics, bool unreadOnly, bool unansweredOnly, bool returnRecordCount);

A few things about the parameters though are worth mentioning.

  • For the forumID parameter you can supply -1 instead of a legit ID. This will cause threads from all forums to be returned.
  • The user parameter, when supplied with an User object of an actual user (e.g. CSContext.Current.User) will filter the issued query so that only threads which the user actually has access to will be returned.
  • ThreadUsersFilter.All will apply no filter, contrary to what it says :)

The GetThreads method returns a ThreadSet object that has a property named Threads on it. This property will return you an ArrayList of Thread objects which you can bind to e.g. a Repeater Control in your UserControl.

Please see the demonstration UserControl for more details on the binding part.

The cool thing about using the GetThreads method (besides the obvious relief of having to dig through the database schema and procedures to return this result yourself) is that you will get full use of the caching and access control mechanisms that CS provides. No worries about performance or security :)

I was thinking about writing a longer article on this topic, so please let me know if that would be interesting, and what specifically you would want to know.

Published Monday, March 28, 2005 5:55 PM by cnordbakk
Filed under:

Comments

 

Off Shot Thoughts said:

For that last few days I've been playing around with modifying the default skin for CommunityServer. ...
April 3, 2005 3:40 AM
 

Chris Hammond said:

July 13, 2005 4:38 PM
 

Chris Hammond said:

July 18, 2005 11:21 AM
 

Chris Hammond said:

August 3, 2005 6:54 PM
Anonymous comments are disabled