Click here to Skip to main content
15,886,689 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 168.7K   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.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Syndication;
using MessageBoard.Web.Properties;
using System.Web;
using System.Globalization;

namespace MessageBoard.Web
{
    // NOTE: If you change the class name "FeedService" here, you must also update the reference to "FeedService" in App.config.
    public class FeedService : IFeedService
    {
        #region IFeedService Members

        public SyndicationFeedFormatter GetLatestMessages(FeedFormat format)
        {
            Uri rootUri = GetRootUri();
            SyndicationFeed feed = new SyndicationFeed(Resources.MessageBoard, Resources.MessageBoardDescription, rootUri);
            feed.Items = from m in MessageSource.GetRecentMessages(0, 10)
                         select CreateSyndicationItem(m, rootUri);
            
            if(format == FeedFormat.Atom)
                return new Atom10FeedFormatter(feed);
            
            return new Rss20FeedFormatter(feed);
        }

        #endregion

        private SyndicationItem CreateSyndicationItem(Message m, Uri rootUri)
        {
            UriBuilder uriBuilder = new UriBuilder(rootUri);
            uriBuilder.Path += "Message.aspx";
            uriBuilder.Query = "id=" + m.Id.ToString(CultureInfo.InvariantCulture);

            var item = new SyndicationItem(m.Subject, m.Text, uriBuilder.Uri, m.Id.ToString(), new DateTimeOffset(m.DatePosted, new TimeSpan(0)));
          
            item.Authors.Add(new SyndicationPerson(m.PostedBy));

            return item;
        }

        private Uri GetRootUri()
        {
            Uri uri = OperationContext.Current.Channel.LocalAddress.Uri;
            UriBuilder builder = new UriBuilder(uri);
            
            StringBuilder pathBuilder = new StringBuilder(builder.Path);
            int indexOfSlash = builder.Path.LastIndexOf('/');
            pathBuilder.Remove(indexOfSlash, builder.Path.Length - indexOfSlash);
            builder.Path = pathBuilder.ToString();

            return builder.Uri;
        }
    }
}
 

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