Sharepoint Webparts AS – Connecting the WebParts - making an RSS Reader Application

Posted on 7/14/2006 @ 5:49 AM in #SharePoint by | Feedback | 10527 views

(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 -

 

Sound off but keep it civil:

Older comments..


On 10/6/2007 1:04:00 PM Andrew Macdonald said ..
-->>> going to skip Atlas/Ajax integration


Hi,


Did you ever get around to writing this bit as I am just in the process of trying to link some web parts and have them communicate between each other using AJAX (without using smart web part) and was looking for ideas as to how I might approach it.

I would be very interested in your views.


On 10/6/2007 2:21:02 PM Sahil Malik said ..
Andrew - No I didn't.


I was waiting for SP1 to get released, because Atlas support was going to be included in that. Unfortunately, it looks like it might not be (which sucks!).

Anyway, there is a work around.

You should watch this blogpost - http://blah.winsmarts.com/2007-10-SharePoint_2007_for_NET_Developers.aspx and suggest any other topics you might come up with. (and be patient, I can only type so fast ;)).


On 10/7/2007 6:21:22 AM Andrew Macdonald said ..
Hay Sahil,

Thanks for the quick reply... I will go and watch that blogpost right now :)

Regards Andy

ps.. you can type as slow as you want... the wise man is the one that waits ;)


On 11/17/2008 5:24:32 AM senthil said ..
hi,


Have you tried of using AJAX in connecting webparts. if so can you share an example.

--senthil