Click here to Skip to main content
15,896,118 members
Articles / Web Development / ASP.NET

Building a Web Message Board using Visual Studio 2008 Part II - Posting messages using Microsoft Word

Rate me:
Please Sign up or sign in to vote.
4.94/5 (41 votes)
31 Dec 2007CPOL23 min read 169.3K   1.3K   122  
This article uses Visual Studio Tools for Office to build a Word Document Template that can be used to post messages to a message board.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using MessageBoard.Properties;

namespace MessageBoard
{
    /// <summary>
    /// Represents a message in the message board
    /// </summary>
    [DataContract]
    public class Message
    {
        public Message()
        {
        }
        
        public Message(int id, string subject, string text, string postedBy, string postedById, DateTime postedDate)
        {
            this.Id = id;
            this.Subject = subject;
            this.Text = text;
            this.PostedBy = postedBy;
            this.PostedById = postedById;
            this.DatePosted = postedDate;
            this.Frozen = true;
        }

        private int _id;

        [DataMember]
        public int Id
        {
            get { return _id; }
            set { CheckImmutable(); _id = value; }
        }

        private string _subject;

        [DataMember]
        public string Subject
        {
            get { return _subject; }
            set { CheckImmutable(); _subject = value; }
        }

        private string _text;

        [DataMember]
        public string Text
        {
            get { return _text; }
            set { CheckImmutable(); _text = value; }
        }

        private string _postedBy;

        [DataMember]
        public string PostedBy
        {
            get { return _postedBy; }
            set { CheckImmutable(); _postedBy = value; }
        }

        private string _postedById;

        [DataMember]
        public string PostedById
        {
            get { return _postedById; }
            set { CheckImmutable(); _postedById = value; }
        }

        private DateTime _datePosted;

        [DataMember]
        public DateTime DatePosted
        {
            get { return _datePosted; }
            set { CheckImmutable(); _datePosted = value; }
        }

        private void CheckImmutable()
        {
            if (Frozen)
                throw new InvalidOperationException(Resources.ObjectFrozen);
        }

        public bool Frozen { get; private set; }

        public Message Freeze()
        {
            this.Frozen = true;
            return this;
        }
    }
}

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