(If you are wondering what this blogpost is about, please read my series on Sharepoint Advanced Webparts)
In my series on Sharepoint Advanced Webparts, you have already looked at writing two webparts -
a) Something that lets you render an RSS Feed. (read here)
b) Something that lets you maintain a list of RSS Feeds. (read here)
The idea being, if somehow these two could communicate with each other, you'd have at your hands a simple RSS-Reader, just like bloglines or newsgator.
For background info, I'd recommend reading. When you are done reading the below, come back here, and continue reading on.
ASP.NET 2.0 WebPart Communication
The Preface to Sharepoint 2007 WebPart communication
------> (Read here) <------
Okay good. Now that you are familiar with the basics of WebPart communication, lets make these two webparts "communication aware".
First, what are we communicating? An RSS Feed, right? Great, go ahead and declare an interface representing that -
public interface IRssFeed
{
string FeedName { get;set;}
string FeedURL { get;set; }
}
Now go to the Provider in your communication, the RssRender webpart, and implement the interface IRssFeed. The implementation is shown as below.
#region IRssFeed Members
public string FeedName
{
get { return feedName ; }
set { feedName = value; }
}
[WebBrowsable(true)] [Personalizable(true)]
public string FeedURL
{
get { return rssUrl; }
set { rssUrl = value; }
}
#endregion
Also, you need a method decorated with the ConnectionProvider attribute. Go ahead and add that as shown below:
[ConnectionProvider("The Provider")]
public IRssFeed GetRssCommunicationPoint()
{
return this as IRssFeed;
}
Now in your OPML Webpart you need a method decorated with the ConnectionConsumer attribute. This is shown as below:
[ConnectionConsumer("TheContent Consumer")]
public void InitializeProvider(IRssFeed provider)
{
theProvider = provider;
}
Now modify the OnPreRender method of the OPMLWebpart do the following:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (theProvider != null)
{
theProvider.FeedURL = rbl.SelectedValue;
if (rbl.SelectedIndex != -1)
{
theProvider.FeedName = rbl.SelectedItem.Text;
}
}
}
Uhh .. and thats about it :). Build/Deploy, add these two WebParts, and set the WebPartManager in Connect DisplayMode. You should see connect menu items appear by each Webpart as shown below.

Click on "Connect" on either, I am going to click on the Connect Verb for the OPML Editor. This should pop open a ConnectionsZone as shown below.

Click on "Create a connection to a provider." Choose "RssImport", and click "Connect".

Click "Close", set the page in Browse display mode.
Bingo, you have at your hands an RSS Reader, just like Bloglines or Newsgator. NEAT !! :-). This can be seen in action below -

Now as an exercise for you, do the same on a WebPage with two WebPartZones, in two columns - the left column being the thinner one holds the OPML Editor, and vice versa.
I am going to skip Atlas/Ajax integration until the very end, depending upon the interest from the audience :-). Next, I will use these webparts we just wrote, and create an RSS Reader in Sharepoint 2007.
Stay tuned.
Thou shalt - 