CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Brendan Tompkins [MVP]

Blog First. Ask Questions Later.

Community Server Homepage Controls

If you read us through our website, you’ve probably noticed that we launched our new homepage yesterday. Community Server didn’t have exactly the controls I needed to create the new homepage, so I had to create new controls that did what I wanted.  Fortunately, CS did gave me the building blocks I needed to quickly assemble the new page.  I wanted to post here the source files, in case anyone wants to create a similar page with Community Server. I created three new controls.  Here’s what they look like on the home page.

Control 1:   FeaturedArticle
Purpose: This control shows one featured article, along with the excerpt and the author’s avatar.
Files Needed : FeaturedArticle.cs, Skin-FeaturedArticle.ascx

Control 2:   AggregateCompactPostList
Purpose: Shows a configurable number of latest and most popular posts.
Files Needed : AggregateCompactPostList.cs, Skin-AggregateCompactPostList.ascx, AggregatePostList.cs, AggregatePostList.ascx

Control 3:   AggregateCompactArticleList
Purpose: Displays an article’s category title, excerpt, and published articles.
Files Needed : AggregateCompactArticleList.cs, Skin-AggregateCompactArticleList.ascx, AggregatePostList.cs, AggregatePostList.ascx

You’ll also need some css styles added to CommunityServer’s style sheet (via default.aspx in the Themes/default/style directory)

All CS files go in the CommunityServerBlogs project in the Controls/AggregateBlogControls directory, and all ascx files go in the CommunityServerWeb project in the Themes/Default/Skins/Blogs directory.

You can download the source files here.  Shoot me an email if you need help implementing this, or if I left anything out.

-Brendan



Comments

David Hayden said:

Absolutely, positively awesome, Brendan!
# June 15, 2005 8:52 AM

Steve said:

Looks awesome! Nice work!
# June 15, 2005 9:50 AM

keithrull said:

i'd be interested to see those source codes! :) *wink* *wink*
# June 15, 2005 10:24 AM

Alex Lowe said:

This is very cool!

I posted a note about it on the new Add-ons forum at CS.org.....

http://communityserver.org/forums/488637/ShowPost.aspx
# June 15, 2005 10:25 AM

John Papa said:

Great work Brendan! Looks nice!
# June 15, 2005 11:11 AM

Scott said:

Very nice. You're helping to make CS into a real, live boy!
# June 16, 2005 9:59 AM

swing said:

When I follow the guidance, copy all .cs files into \src\Blogs\Controls\AggregateBlogControls and copy all .ascx files into \src\Web\Themes\Blogs...(right? ), then I open CS solution and add those files into, then recompile, there was two errors in AggregateCompactPostList.cs

Line 17 and line 175: Webblogs.GetWeblogGroup() and Weblogs.GetWeblogs() method have been change when upgrade from cs1.0 to cs1.1, so I modified these two lines, and I can go through compiling, but when I visit my new home page, there was an exception "skin file not found"

I still working on it, if someone done, please tell me what should I do, thanks
# June 16, 2005 1:30 PM

Brendan Tompkins said:

Swing,

Skins for these aggregate controls go in the

Themes/default/Skins/Blogs directory. It was incorrect in the initial post, but I've updated it.

B
# June 16, 2005 2:15 PM

swing said:

When I copy .ascx files to Themes/Default/Skins/Blogs directory, it runs pretty well, but line 144 & 175 in AggregateCompactPostList.cs need to change before compile with CS1.1.
# June 16, 2005 5:45 PM

Phosphorus said:

I've been trying to implement these controls for the last day and a half, and I almost have it working properly.

Currently, I am hung up on getting the "Featured Article" control working.

In the default.aspx page that you supplied, the <Blog: FeaturedArticle/> control doesn't include any mention of a BlogId. Without the BlogId, the stored procedure is passed a 0, so nothing is ever returned.

I had to add this line:
query.BlogID = this.blogId ; (on line 137 of FeaturedArticle.cs)

and BlogId = "4"

to the <Blog:FeaturedArticle> tag in the aspx code.

Even after adding a BlogId = number element in the aspx, the stored procedure that is used to get the right article also looks for the "PostLevel" value in the cs_posts table.

The PostLevel field seems to correspond to the number of comments that have been posted about a given article. The strange thing is that the stored procedure (cs_weblog_Postset) will not return any records unless the PostLevel is not 1.

See the last line in the sproc:

SELECT @TotalRecords = Count(PostID) FROM cs_Posts (nolock) WHERE IsApproved = 1 AND ThreadID = @ThreadID and PostLevel <> 1

So basically, on a brand new article (with no comments), @TotalRecords will equal 0 (since PostLevel equals 1). FeaturedArticle.cs reads that @TotalRecords output paramater and when it sees that it is 0, it skips over the guts of the code that renders the post to the page.

Also, for others that are implementing these controls and end up with a "the requested resource could not be found" error on your default.aspx page, make sure you go into the .aspx and set the "BlogId" and "CategoryId" tags to valid values. You will have to poke around in your database to find them.
# June 17, 2005 2:15 PM

Phosphorous said:

I should mention that I am using the 1.0 source, so that might be the cause of most of my problems.
# June 17, 2005 2:23 PM

Phosphorous said:

I just upgraded to the 1.1 source and ran into the same issues that were mentioned above. Additionally, I had to comment out line 152 in featuredarticle.cs:

//this.authorLink.ImageUrl = we.User.AvatarUrl;

It seems that the User object is no longer available in that context. Will have to look into the new way of getting it.

Oh yeah, and the layout of the home page is different in 1.1, so the css gets messed up. But other than that, the other problems associated with PostLevel seem to have been fixed.
# June 17, 2005 4:19 PM

Brendan Tompkins said:

Phosphorus,

Thanks for taking the time to look at this. I just started migrating to 1.1 today, and did see that the user object was removed from interface.

This would certainly be problematic for the Avatar.

Sorry about the other issues. Not sure why you were seeing this behavior. If I get anywhere, with 1.1 I'll re-post the code.

Hey, it worked on my machine. ;P
# June 17, 2005 5:35 PM

Brendan Tompkins said:

Last week, I posted the code for our Community Server Homepage Controls

Control 1: FeaturedArticlePurpose:...
# June 22, 2005 6:58 AM

Brendan Tompkins said:

Last week, I posted the code for our Community Server Homepage Controls

Control 1: FeaturedArticlePurpose:...
# June 22, 2005 7:00 AM

Off Shot Thoughts said:

After much messing around and getting the main page for this sitelooking like I want, I think I'm ready...
# June 27, 2005 3:08 PM

Off Shot Thoughts said:

After much messing around and getting the main page for this sitelooking like I want, I think I'm ready...
# June 27, 2005 3:09 PM

Off Shot Thoughts said:

After much messing around and getting the main page for this sitelooking like I want, I think I'm ready...
# June 27, 2005 3:12 PM

Off Shot Thoughts said:

After much messing around and getting the main page for this site looking like I want, I think I'm ready...
# June 27, 2005 3:14 PM

Off Shot Thoughts said:

After much messing around and getting the main page for this site looking like I want, I think I'm ready...
# June 27, 2005 3:17 PM

Off Shot Thoughts said:

After much messing around and getting the main page for this site looking like I want, I think I'm ready...
# June 27, 2005 3:17 PM

Off Shot Thoughts said:

After much messing around and getting the main page for this site looking like I want, I think I'm ready...
# June 29, 2005 3:39 PM

Off Shot Thoughts said:

Community Server,Web,Development,Blogs
# July 3, 2005 2:04 AM

Off Shot Thoughts said:

Community Server,Web,Development,Blogs
# July 10, 2005 1:34 AM

Off Shot Thoughts said:

Community Server,Web,Development,Blogs
# July 10, 2005 1:40 AM

Off Shot Thoughts said:

Community Server,Web,Development,Blogs
# July 10, 2005 1:40 AM

Off Shot Thoughts said:

After much messing around and getting the main page for this site looking like I want, I think I'm ready...
# July 10, 2005 1:42 AM

Off Shot Thoughts said:

After much messing around and getting the main page for this site looking like I want, I think I'm ready...
# July 10, 2005 1:43 AM

Off Shot Thoughts said:

After much messing around and getting the main page for this site looking like I want, I think I'm ready...
# July 10, 2005 10:11 PM

Kevin Dan's Blog said:

Not with a little twist, Together.blogdns.com ( a newly registered domain name) can be reached all over...
# August 19, 2005 1:27 PM

Kevin Dan's Blog said:

Now with a little twist, together.blogdns.com (a newly registered domain name) can be reached all over...
# August 19, 2005 1:28 PM

Nix's Blog said:

Les blogs CodeS-SourceS viennent d'&#234;tre migr&#233; sur CommunityServer. (Peut-&#234;tre avez-vous remarqu&#233; un &quot;l&#233;ger&quot;...
# October 21, 2005 6:34 AM

Nix's Blog said:

Les blogs CodeS-SourceS viennent d'&#234;tre migr&#233; sur CommunityServer. (Peut-&#234;tre avez-vous remarqu&#233; un &quot;l&#233;ger&quot;...
# October 21, 2005 6:35 AM

Nix's Blog said:

Les blogs CodeS-SourceS viennent d'&#234;tre migr&#233; sur CommunityServer. (Peut-&#234;tre avez-vous remarqu&#233; un &quot;l&#233;ger&quot;...
# October 21, 2005 8:54 AM

Nix's Blog said:

Les blogs CodeS-SourceS viennent d'&#234;tre migr&#233; sur CommunityServer. (Peut-&#234;tre avez-vous remarqu&#233; un &quot;l&#233;ger&quot;...
# October 27, 2005 3:17 PM

Jacob Reimers' Weblog said:

I adapted the Featured Article and AggregateCompactList to User Controls from Brendan Tompkin's originals and added them to the file list.
# March 6, 2006 7:54 AM

Jacob said:

I posted an adaptation of your Featured Article and AggregateCompactList at http://www.reimers.dk/blogs/jjrdk/archive/2006/03/06/113.aspx

Your controls looked great, but didn't work for CS v 2.0 so I adapted them to User Controls.
Hope you approve.
# March 6, 2006 7:57 AM

Brendan Tompkins said:

Jacob.. Thanks for this, very cool! BTW, you can get the source for CS2 in the SDK.

Brendan
# March 6, 2006 8:43 AM

Brendan Tompkins said:

This weekend we upgraded to Community Server 2.0 here at CodeBetter.&amp;nbsp;&amp;nbsp;We have a new improved...
# March 20, 2006 12:15 PM

murat said:

I tried everything but it reteurns error like this:

-----------------------------------------------------

[NullReferenceException: Object reference not set to an instance of an object.]

  CommunityServer.HomePageControls.FeaturedArticle.DataBind() +129

  CommunityServer.HomePageControls.FeaturedArticle.OnLoad(EventArgs e) +50

  System.Web.UI.Control.LoadRecursive() +47

  System.Web.UI.Control.LoadRecursive() +131

  System.Web.UI.Control.LoadRecursive() +131

  System.Web.UI.Control.LoadRecursive() +131

  System.Web.UI.Control.LoadRecursive() +131

  System.Web.UI.Control.LoadRecursive() +131

  System.Web.UI.Control.LoadRecursive() +131

  System.Web.UI.Control.LoadRecursive() +131

  System.Web.UI.Control.LoadRecursive() +131

  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

--------------------------------------------------

# December 31, 2006 3:04 PM

justin said:

Does this work with 2007 version of CS?

# April 13, 2007 9:35 AM

AlexNC said:

Thank you so much for sharing this!!!

# June 7, 2007 3:38 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Brendan Tompkins

Brendan has been programming with .NET since the first public beta and is owner and operator of Port Technology Services, a consultancy company providing .NET application development services to the Maritime industry. In July, 2007, he was awarded the Microsoft MVP award for ASP.NET. He's also a proud co-founder of failed .COM startup Intrinsigo, and has had a hand in the failure of numerous other businesses. He currently runs CodeBetter.Com and Devlicio.us, and lives in Norfolk, Virgina with his wife Tiara and son Ian.

View Brendan's profile on LinkedIn

Check out Devlicio.us!