Connecting two web parts declaratively using a file provisioning module

Posted: 31st October 2011 in Configuration, Deployment, SharePoint, Web Parts

I just like to start by saying that this post is not ground breaking. However, when I tried to do this it did take me a while to find the answer, so I thought I’d just blog to add it to the grey matter.

As I’m sure you are all aware you can provision multiple files with preconfigured web parts by using a SharePoint module’s element file and a web part page as a template, by targeting the web part zones on the web part page.

However, trying to connect these caused me a bit of problems. In the end though it was quite straight forward. And can be done by specifying the following attributes in the code snippets and the descriptions given in the table below.

WebPartConnection
  1. <WebPartConnection ConsumerConnectionPointID="MediaSearchConsumer" ConsumerID="MediaResultsWebPart"
  2.                          ProviderConnectionPointID="MediaSearchProvider" ProviderID="MediaSearchWebPart" ID="MediaSearchConnector"/>

Web Part Consumer
  1.       <AllUsersWebPart WebPartZoneID="MiddleZone2" WebPartOrder="0" ID="MediaResultsWebPart">
  2.         <![CDATA[<?xml version="1.0" encoding="utf-8"?>
  3. <webParts>
  4.   <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"&gt;
  5.     <metaData>
  6.       <type name="Instalec.SharePoint.WebParts.MediaResultsWebPart.MediaResultsWebPart, Instalec.SharePoint.WebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9e5b38b443f03fff" />
  7.       <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
  8.     </metaData>
  9.     <data>
  10.       <properties>
  11.         <property name="Title" type="string">Media Search Results</property>
  12.         <property name="Description" type="string">Web part to display the results from the media search</property>
  13.          <property name="Hidden" type="bool">True</property>
  14.           <property name="AllowHide" type="bool">True</property>
  15.       </properties>
  16.     </data>
  17.   </webPart>
  18. </webParts>
  19. ]]>
  20.       </AllUsersWebPart>

Web Part Provider
  1.     <AllUsersWebPart WebPartOrder="1" WebPartZoneID="MiddleZone" ID="MediaSearchWebPart">
  2.             <![CDATA[<webParts>
  3.   <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"&gt;
  4.     <metaData>
  5.       <type name="Instalec.SharePoint.WebParts.MediaSearchWebPart.MediaSearchWebPart, Instalec.SharePoint.WebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9e5b38b443f03fff" />
  6.       <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
  7.     </metaData>
  8.     <data>
  9.       <properties>
  10.         <property name="Title" type="string">Media Search</property>
  11.         <property name="Description" type="string">My Visual WebPart</property>
  12.       </properties>
  13.     </data>
  14.   </webPart>
  15. </webParts>
  16. ]]>
  17.         </AllUsersWebPart>

Connection Consumer Attribute
  1. [ConnectionConsumer("The Search Criteria", "MediaSearchConsumer")]
  2.         public void IMediaSearchConsumer(IMediaSearch mediaSearch)

Connection Provider
  1. [ConnectionProvider("The Search Criteria", "MediaSearchProvider")]
  2.      public IMediaSearch IMediaSearchProvider()
  3.      {
  4.          return this;
  5.      }

 

ConsumerID ID specified in the AllUserWebPart element as seen in the Web Part Consumer above
ConsumerConnectionPointID The ID of the ConnectionConsumerAttribute seen above
ProviderID ID specified in the AllUserWebPart element as seen in the Web Part Provider above
ProviderConnectionPointID The ID of the ConnectionProviderAttribute seen
above
ID This can be any value but will not work without it

Job done… Smile

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s