Welcome to MSDN Blogs Sign in | Join | Help

Creating a WebPart that works both as a consumer and a provider

If you ever have to create a web part that needs to act both like a provider and a consumer in which case you'll need to implement more than one Interface, you'll need to create separate classes that implement the separate interfaces...

To make a web part work both as a provider and a consumer you'll need to create three classes...

1) public class CellProviderInterface : ICellProvider
2) public class CellConsumerInterface : ICellConsumer
3) public class WebPart1 : Microsoft.SharePoint.WebPartPages.WebPart

In classes CellProviderInterface and CellConsumerInterface you'll have to implement the ICellProvider and ICellConsumer interfaces.

In your WebPart class you need to instantiate the two classes that implement the ICellProvider and ICellConsumer (viz. CellProviderInterface and CellConsumerInterface)

//instantiate your classes
CellConsumerInterface oCellConsumerInterface = new CellConsumerInterface();
CellProviderInterface oCellProviderInterface = new CellProviderInterface();

And When you register your interface's in the overridden EnsureInterfaces() you need use the instances of these two classes.

public override void EnsureInterfaces()
{
 // Register the ICellProvider interface
 RegisterInterface("CellProvider_WPQ_",
  "ICellProvider",
  WebPart.UnlimitedConnections,
  ConnectionRunAt.Server,
  oCellProviderInterface,
  "CellProvider_WPQ_",
  "Provides a cell to",
  "Provides a cell of data");


 // Register the ICellConsumer interface.
 RegisterInterface("CellConsumer_WPQ_",
  "ICellConsumer",
  WebPart.UnlimitedConnections,
  ConnectionRunAt.Server,
  oCellConsumerInterface,
  "CellConsumer_WPQ_",
  "Consumes a cell from",
  "Consumes a cell of data");
}

Here’s some sample code that does something very similar….

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spptsdk/html/smpxCreateConnectableWPMultipleInterface_SV01080585.asp?frame=true

Jeelani

Published Friday, November 05, 2004 7:48 PM by mjeelani
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Creating a WebPart that works both as a consumer and a provider

Monday, July 24, 2006 6:47 AM by IWebPartField
Now that the recommended interfaces have been changed to the IWebPartField (and other IWebPartXXX interfaces) I am wondering how this can be done most effectively this way.
I am also wondering how you can make sure that the events fire in the order you desire. If you have a WebPart that is both consumer and provider it is most likely the "middle" component in your communication: It receives a value from it's provider, uses this value for some purpose, and sends it's own value on to the consumer for which it is provider. But with IWebPartField the events fire in the reverse order. The latter WebPart requests the value before the "middle" WebPart has recievied its value and made itself ready for sending its own value as the provider.

# wiry Bournemouth

Wednesday, November 15, 2006 3:35 PM by wiry Bournemouth

-- Build to Perform, Architect to Evolve --

I do not agree. Go to http://www.hotelsforum.info/amid_United%20Kingdom/tetter_England/wiry_Bournemouth_1.html

# bred Bedford

Friday, November 17, 2006 9:37 AM by bred Bedford

-- Build to Perform, Architect to Evolve --

I do not agree. Go to http://www.hotelscenter.info/nub_United%20Kingdom/recast_England/bred_Bedford_1.html

# isoseismal Weimar

Friday, January 19, 2007 9:55 AM by isoseismal Weimar

# aerodrome London

Wednesday, March 28, 2007 10:02 AM by aerodrome London

-- Build to Perform, Architect to Evolve --

I do not agree. Go to http://www.getworkz.info/boy_United%20Kingdom/pyroxene_England/aerodrome_London_1.html

# I disagree

Tuesday, August 14, 2007 3:41 PM by warsaw hotels

-- Build to Perform, Architect to Evolve --

I do not agree. Go to http://apartments.waw.pl/

# re: Creating a WebPart that works both as a consumer and a provider

Thursday, February 07, 2008 12:38 PM by Mike Cottenier

Mohammed

I've been trying to build a provider/consumer web part using the approach you outline in this blog.  However, I am having some difficulty.  The link to the example is broken.  Can you update the link or provide a working example?  I realize this approach is now obsolete, but unfortunately, I'm stuck with obsolete development and operational environments.

Any help you can provide will be greatly appreciated.

Mike

Michael.Cottenier@us.army.mil

# A web part that is a consumer and provider at the same time. | keyongtech

# [WSS2003] webpart cell provider et consummer | hilpers

Thursday, January 22, 2009 9:38 AM by [WSS2003] webpart cell provider et consummer | hilpers

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker