Programmatically Configure RSS Settings For a List



Introduction:

Really Simple Syndication (RSS) is used for transmitting information across the internet and intranets. We can also subscribe to RSS Feeds from SharePoint libraries, lists, and other elements. We can use an RSS Viewer Web Part to display an RSS Feed on a SharePoint site. An RSS Viewer Web Part provides a convenient way to view information from many sources on a single page.

In this article we will be seeing how to programmatically configure RSS settings for the SharePoint list.

Configure RSS settings for the list:

  1. Go to the SharePoint List => List Settings => Communication => RSS settings.

    RSSShare1.gif
     
  2. Open Visual Studio 2010.
  3. Go to File => New => Project.
  4. Select Console Application template from the installed templates.
  5. Add the following references.

    • Microsoft.SharePoint

  6. Add the following namespaces.

    • using Microsoft.SharePoint;

  7. Replace Program.cs with the following code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;

    namespace RSSSettings
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (SPSite site = new SPSite("http://serverName:1111/sites/Sample/"))
                {
                    using (SPWeb web = site.RootWeb)
                    {
                        SPList list = web.Lists.TryGetList("Contributor");
                        if (list != null)
                        {
                            //Configure RSS settings                       
                        }
                        else
                        {
                            Console.WriteLine(list.Title + " does not exists in the site");
                        }
                        Console.ReadLine();
                    }
                }
            }
        }
    }

//Enable RSS settings

RSSShare1.1.gif

list.EnableSyndication = true;

list.Update();

// Truncate multi-line text fields to 256 characters   

RSSShare2.gif

list.RootFolder.Properties["vti_rss_LimitDescriptionLength"] = 1;

// Title

RSSShare3.gif

list.RootFolder.Properties["vti_rss_ChannelTitle"] = "Contributor List RSS";

// Description

RSSShare4.gif

list.RootFolder.Properties["vti_rss_ChannelDescription"] = "RSS feed for Contributor List"; 

// Image URL

RSSShare5.gif

list.RootFolder.Properties["vti_rss_ChannelImageUrl"] = "/sites/Sample/_layouts/images/siteIcon.png";

// Maximum items to include

RSSShare6.gif

list.RootFolder.Properties["vti_rss_ItemLimit"] = 15; 

// Maximum days to include

RSSShare7.gif

list.RootFolder.Properties["vti_rss_DayLimit"] = 3;

list.RootFolder.Update();

// For Document Library

// Include file enclosures for items in the feed?

RSSShare8.gif

list.RootFolder.Properties["vti_rss_DocumentAsEnclosure"] = 0;

// Link RSS items directly to their files?

list.RootFolder.Properties["vti_rss_DocumentAsLink"] = 0;