How we did it: – Part 5: Mavention RSS

A part of building an Internet-facing website is notifying your visitors about new content. Using RSS/Atom feeds is a common way to deliver new content to your audience. Find out how we created RSS for our brand new website without a single line of custom code!

One of the things that made it for the first release of our website was an RSS feed that would deliver the most recent content on our website to our readers. Based on the content that we would include in the first release, we wanted to provide a single RSS feed that would aggregate recent news and blog posts.

As you might have know SharePoint provides a few different approaches for creating RSS feeds. The very first that we did was to research those possibilities to see which one would fit our requirements the best.

List RSS feed

First of all there is the RSS feed option on Lists/Libraries.

List RSS Feed button highlighted on the Ribbon.

With just a few clicks it allows you to configure an RSS feed for the contents of your list. Although you cannot configure everything the most important options are there what allows content editors to create RSS feeds without the involvement of the IT.

RSS Feed generated using the List RSS Feed option.

The great thing is that a List RSS feed can be read by anonymous users, so it’s definitely something that you might consider for using on an Internet facing website. In our scenario it was however insufficient: since news and blogs are spread over multiple sites we had to look for another solution that would allows us to provide an aggregated feed.

Search Results RSS

Another approach to provide an RSS feed on a SharePoint website is to use search. If you navigate to a standard search results page in SharePoint 2010 one of the default actions links is the link to display the search results as an RSS feed:

Red arrow pointing to the RSS link on a search results page in SharePoint 2010.

What we could do in order to utilize search to display an RSS feed of news and blogs would be to create a custom Search Scope that would include only content from those two sites. To display the results we would use ContentClass:STS_ListItem_850 as the search query which would display all Publishing Pages.

All Publishing Pages displayed using a fixed keyword search query.

The RSS would then return the same results but then formatted as an RSS feed which our visitors could use to get the latest information about content on our website.

RSS Feed generated for search results.

Although, just like the List RSS feed, the Search Results RSS feed is accessible for anonymous users, it has one serious downside. By default search results are ordered by relevance which is what you want in most cases, but not when providing an RSS feed for the most recent content. And although the control responsible for generating the Search Results RSS allows you to specify whether you want to sort results by relevance or by date, it’s not something you can configure using query string parameters. The control is embedded in an Application Page and the only way to work around this is to create a new Application Page and configure the control to sort results results by date.

Is it time to build something?

Although I am developer and love to create new things, I think that custom development should be the last choice. Using something that’s available out of the box is better for everyone: the customer gets something that has been extensively tested by the Product Team and is supported by Microsoft, and you can focus on stuff that’s really unique and creative instead of reinventing the wheel.

SharePoint 2010 provides us with one more approach that you can use to create an RSS feed.

Creating RSS feeds with Content Query Web Part

Content Query Web Part allows you to create content aggregations. Additionally it gives you the option to enable the Feed which allows users to view the same content aggregation as an RSS feed. Whenever the content gets updates, users will be automatically presented with an up-to-date RSS feed.

In our scenario we wanted to create a single RSS feed for news and blogs. Since we didn’t have such overview on the public part of our website, we decided to create a hidden page that would have the Content Query Web Part on it.

By default the CQWP allows you to filter the content aggregation based on a single Content Type. Because in our scenario we had two Content Types (News and Blog Post) we decided to use the QueryOverride property and set the query ourselves to include Pages from both News and Blog Post Content Type:

            <FieldRef Name='ContentTypeId' />
            <Value Type='Text'>0x010100C56...</Value>
            <FieldRef Name='ContentTypeId' />
            <Value Type='Text'>0x010100C56...</Value>
    <FieldRef Name='Created' Ascending='FALSE'/>

Once we had the query in place we enabled the Feed and set its name to Mavention.

The last thing that we had to do was to configure the CQWP to include content from our fields in the RSS feed. To simplify reading articles in RSS readers we decided that we would provide full content rather than excerpts. For this we had to include the Page Content field in the RSS feed.

If you have worked with CQWP in the past, you know that in order to include custom fields in the query, you would have to set values of the CommonViewFields and DataColumnRenames properties. The CommonViewFields property allows you to retrieve content from non-standard fields where the DataColumnRenames property allows you to map those values to standard fields so that you can reuse XSL templates across different aggregations. Back in SharePoint 2007 XSL Item Styles for the CQWP were bound to Internal Names of fields so this was the necessary approach if you wanted to use the standard XSLT for CQWP RSS feeds. The great news is that things got easier in SharePoint 2010.

The Content Query Web Part in SharePoint 2010 has the slots capability which allows you to map fields to XSLT through the properties panel. This allows you to create semantic XSL templates and configure the mapping outside of XSLT. Thanks to the slots capability you are no longer required to use the CommonViewFields and DataColumnRenames properties.

In our configuration we used the standard Image on left Item style and used the following slots mappings:

Slots mapping for Mavention RSS Content Query Web Part

Using the above configuration allowed us to configure the RSS without a single line of code!

Mavention RSS feed generated using the Content Query Web Part.

The finishing touch: configuring the URL and publishing the feed

You might have noticed that the URL of our RSS feed is This is way something different than the default URL that the Content Query Web Part uses for RSS which is more like\_layouts/feed.aspx?xsl=1&web=%2F&page=some\_guid&wp=some\_other\_guid&pageurl=%2FPages%2Fsomepage.aspx. To simplify the URL we used a simple rewrite rule with URL Rewrite.

URL Rewrite rule for rewriting the short RSS URL on to the URL generated by the Content Query Web Part.

Configuring the URL Rewrite allowed us not only to shorten the URL and make it easier to remember but also to decouple it from the approach that we chose. Should we ever need to use a different approach than the CQWP all we would have to do is to configure the RSS feed and change the RSS feed URL in the rewrite URL. On the outside we could keep using the same URLs without our visitors having noticed anything.

The last thing that we did was to make the RSS available to our readers. We did this by adding the following line of markup to our Master Page:

<link rel="alternate" type="application/rss+xml" title="Mavention" href="<%= Url("~SiteCollection/rss") %>" />

And that’s it: a fully functional RSS feed for Mavention News and Blogs without a single line of custom code!

Mavention RSS feed

Technorati Tags: SharePoint 2010,Web Content Management,Mavention

Others found also helpful: