Click here to Skip to main content
15,896,455 members
Articles / Web Development / CSS

Building a Web Message Board using Visual Studio 2008, Part I - The Basic Message Board

Rate me:
Please Sign up or sign in to vote.
4.90/5 (83 votes)
30 Dec 2007CPOL47 min read 376.7K   3.7K   333  
This article builds a web based message board and uses several new technologies introduced with Visual Studio 2008 such as LINQ, WCF Web Programming, WCF Syndication, ASP.NET ListView, ASP.NET DataPager etc.
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text.RegularExpressions;
using MessageBoard.Web;

/// <summary>
/// A utility class for formatting data
/// </summary>
public static class Utility
{
    public static String GetFormattedTime(DateTime dateTime)
    {
        return TimeZoneUtility.ConvertToCurrentTimeZone(dateTime).ToString("MMMM dd, MM:hh tt");
    }

    public static String GetFormattedText(string text)
    {
        if (String.IsNullOrEmpty(text))
            return String.Empty;


        return Regex.Replace(HttpUtility.HtmlEncode(text), @"\r\n|\n|\r", "<br/>");
    }

    public static String GetPreviewText(object textObject)
    {
        string text = textObject as string;

        if (String.IsNullOrEmpty(text))
            return String.Empty;

        //Extract around fifty words and add ...
        string extract = text.Substring(0, Math.Min(150, text.Length));

        if (text.Length > 150)
            extract += "...";

        extract = Regex.Replace(HttpUtility.HtmlEncode(extract), @"\r\n|\n|\r", "<br>");


        return extract;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions