Jaa


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….

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

Jeelani

Comments