Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a couple of webparts on a page, XsltListViewWebPart and SPSlicerTextWebPart instances. I need to programmatically connect the filter (slicer) to the xslt webpart. When I do so, I need a transformer to transform the filtervalues to the correct format. I use the TransformableFilterValuesToParametersTransformer for this. The connect code is:

/// <summary>
/// Connects two webparts to each other
/// </summary>
/// <param name="consumerWebPart">The webpart which will consume the data</param>
/// <param name="consumerInterfaceType">The type of interface the consumer endpoint should have</param>
/// <param name="providerWebPart">The webpart which will provide the data</param>
/// <param name="providerInterfaceType">The type of interface the provider endpoint should have</param>
public void ConnectBusinessDataWebParts(
  System.Web.UI.WebControls.WebParts.WebPart consumerWebPart,
  string consumerConnectionPoint,
  System.Web.UI.WebControls.WebParts.WebPart providerWebPart,
  string providerConnectionPoint,
  WebPartTransformer transformer)
{
  // Get the connection point for the consumer.
  System.Web.UI.WebControls.WebParts.ConsumerConnectionPointCollection consumerConnections =
      wpmngr.GetConsumerConnectionPoints(consumerWebPart);

  ConsumerConnectionPoint consumerConnection = null;
  foreach (ConsumerConnectionPoint cpoint in consumerConnections)
  {
    if (cpoint.ID == consumerConnectionPoint)
    {
      consumerConnection = cpoint;
      break;
    }
  }

  // Get the connection point for the provider.
  System.Web.UI.WebControls.WebParts.ProviderConnectionPointCollection providerConnections =
      wpmngr.GetProviderConnectionPoints(providerWebPart);
  ProviderConnectionPoint providerConnection = null;
  foreach (ProviderConnectionPoint ppoint in providerConnections)
  {
    if (ppoint.ID == providerConnectionPoint)
    {
      providerConnection = ppoint;
      break;
    }
  }

  // when a transformer was used; create a new connection based on it; otherwise without one
  if (transformer != null)
  {
    Microsoft.SharePoint.WebPartPages.SPWebPartConnection newConnection =
      wpmngr.SPConnectWebParts(
        providerWebPart, providerConnection,
        consumerWebPart, consumerConnection,
        transformer);

    wpmngr.SPWebPartConnections.Add(newConnection);
  }
  else
  {
    Microsoft.SharePoint.WebPartPages.SPWebPartConnection newConnection =
      wpmngr.SPConnectWebParts(
          providerWebPart, providerConnection,
          consumerWebPart, consumerConnection);
  }
}

This gives me the following exception: The transformer type "Microsoft.SharePoint.WebPartPages.TransformableFilterValuesToParametersTransformer" is not allowed to be used on this page.

Which is weird, because when I connect the webparts through the interface it all works fine and an instance of the same TransformableFilterValuesToParametersTransformer is added. I also checked all properties and stuff, everything matches with what the GUI creates when I couple things in there.

Update 1: I used reflector to check what's going on inside. The problem seems to lie with the !base.AvailableTransformers.Contains(type)) check. That returns false becase the AvailableTransformers collection doesn't contain the transformer I need. This collection is created upon instantiation, when my page is still empty. The available transformers are read from the webparts which aren't there yet. After that, the collection doesn't seem to be refreshed when new webparts are added.

Update 2: Crap, doesn't work. A simple solutions seems to be reinstantiation of the entire SPLimitedWebPartManager object, which will force the collection to reread the webpart transformers. I'm going to try that next.

Update 3: sadly, I still don't have it working properly

share|improve this question
    
Where do you run this code? –  Wictor Wilen MCA MCM MVP May 9 '11 at 2:41
add comment

1 Answer

I've also had such issue. I created Command Line application and tried to go through pages and update connections, but it failed.

I found only one solution - create feature instead of command line application:

  1. I created site scope feature which removes old connections from WebParts and sets new connections in feature's FeatureActivated method. I've done similar actions as described in your question to connect WebParts.
  2. Deployed, then activated in particular site collection and then removed from SharePoint.
share|improve this answer
    
So the same code worked in a feature but not in a commandline app? Could have something to do with SharePoint context, I'm running this code from a custom WCF service (in context though). –  Jasper May 12 '11 at 6:42
    
Sorry to mark this unanswered, but I deployed the code I was using to the production farm where it breaks again. I think it has something todo with security / credentials instead of the transformer type not being allowed. –  Jasper May 30 '11 at 10:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.