.NET Threaded Forum Source Code

By Robbe D. Morris

Printer Friendly Version

Robbe Morris
Robbe & Melisa Morris
As you know, NullSkull has it's own custom built threaded forum written in classic ASP.  Eventually, we look to migrate NullSkull over to .NET since both Peter Bromberg and I work almost exclusively in C# at our regular jobs.  Rather than just write a threaded .NET forum for our site, I decided to put one together that would be extremely easy for our site visitors to integrate into their own web sites.
The source code contains no web.config, global.asax or other special configuration files that would conflict with your existing web site code.  To give you a look at other ways to write ASP.NET code, code behind wasn't used.  A huge percentage of the code is contained in C# class libraries that implement the System.Web.UI.Page class along with basic HTML in the standard .aspx or script only pages.  You'll be able to see how to wire up some of the most common server side events in non ASP.NET project oriented classes that get fired when a page loads.  I think you'll find that this coding methodology will make it easy for you to use the code as is, convert it to code behind, or convert it to script only pages.
 


 
All of the session and application variables are referenced as properties of the NullSkull.Forums.Session class.  The email address and database connection strings for the site are referenced here as well.  The NullSkull.Forums.Utilities class holds a variety of commonly used methods for data access, data edits, and sending email (if you have the SMTP Service enabled on your server).  The NullSkull.Forums.ForumError class holds methods used to display information should a runtime error occur.  It will redirect the user to ForumError.aspx which you can customize as needed.  All three of these classes form part of an inheritance chain held together in the NullSkull.Forums.Main class.
The UI oriented pages all use the NullSkull.Forums.Page class.  The left, right, top, and bottom sections of each page are generated in this class for every page.  Plug in your own graphics, banner ads, menu items, etc. in the appropriate class methods.  You'll also see a method named NullSkull.Forums.Page.SetForumTopicsArray() which loads a hard coded list of forum topics.  If you need to add records to the ForumTopic table, you'll to add them here as well.  If your ForumTopic table changes more than ours (changed only twice in 3 years), then you'll want to look into storing these values in an external XML file, cached dataset, or some other methodology.
The database used to store forum posts is SQL Server 2000.  Much of it's database schema is patterned after an old sqlteam.com article from a couple of years ago.  I've added some columns and made a several code adjustments to clean it up.  But, I kept enough of their code to warrant mentioning it here.  I've also added Full-Text search capabilities.  It will give you a good start on learning how to run Full-Text searches and rank the results.  If you need to enhance the Full-Text search capability, The Guru's Guide to Transact-SQL has a great chapter on this subject.
 
Installation Steps For Web Site Files
 
1.Download the .NET Forum Source Code And Installation Scripts and unzip the contents to the root folder of your website.  All of the source is included in the zip file as well.
2.Make sure that you have Full-Text search installed and that Indexing Service is running.  If you need help with setting this up, read Peter Bromberg's article on SQL Server Full-Text Search here at NullSkull.com.  Using SQL Server Query Analyzer, logon to the master database and run installDatabase.sql to create the database.  Remember to set the paths of your .mdf and .ldf files.  This is located in the first few lines of the script.  I've set them to the root of the C:\ drive as a default.  All of the appropriate permissions and cross reference table entries will also be created for you.
If Full-Text Search is properly installed and configured for your SQL Server instance, run the installFullTextCatalog.sql script.  This will create a couple of stored procedures and the initial full text catalog for the ForumPost table.  You should configure the stored procedure RePopulateFullTextCatalog to run in your job scheduler once a day to automatically rebuild your full text catalog as it's contents for search capabilities are not updated in real time.  When testing the forum, you'll also need to execute RePopulateFullTextCatalog after you've made a few test posts before any search results will be returned.
3.Move the SQL script files installDatabase.sql and installFullTextCatalog.sql to a folder outside of your website or simply delete them.
4.Browse to http://localhost/eggheadcafeforums/default.aspx to test the forum out by creating an account for yourself.
 
Summary
There you have it.  The basic groundwork for your own .NET threaded forum.  Feel free to take the bits and pieces you need to create your own production ready application.

Robbe has been a Microsoft MVP in C# since 2004.  He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.