我在SharePoint Designer中创建了一个简单的自定义页面布局,在每个区域添加了几个Web部件区域和自定义Web部件。
这些Web部件具有自定义提供者 - 使用者接口集。我在SharePoint Designer中配置了Web部件之间的连接(使用“添加连接”向导),并保存了页面布局。
之后,我检查了布局并在SP的网络界面中批准了它。
最后,我根据布局创建了一个发布页面,但未设置Web部件之间的连接。我可以手动设置连接,它工作正常,但我希望在我根据布局创建的每个页面上自动设置连接。
这是预期的行为吗?如果是这样,有没有办法以编程方式或声明方式自动配置连接?
我缺少一步吗?
答案 0 :(得分:0)
可以在SharePoint中设置连接,但不是那么容易。以下是我项目的代码。 首先,我们需要一些方法来为消费者领域和提供者领域创建变换器:
private TransformableFilterValuesToParametersTransformer CreateTransformer(String consumerFieldName, String providerFieldName)
{
TransformableFilterValuesToParametersTransformer filterToParameterTransformer =
new TransformableFilterValuesToParametersTransformer();
// The private fields '_consumerFieldNames' and '_providerFieldNames' must be set for the web part connection to work.
// Having reflected the TransformableFilterValuesToParametersTransformer it seems that the only place this is set is within a
// nested wizard class (this seems to be the wizard that runs when the connection is created via the SharePoint UI) so although
// this is not pretty it looks to be the only way...
try
{
string[] _consumerFieldNames = new string[1];
_consumerFieldNames[0] = consumerFieldName;
FieldInfo conFld = typeof(TransformableFilterValuesToParametersTransformer).GetField("_consumerFieldNames", BindingFlags.Instance | BindingFlags.NonPublic);
conFld.SetValue(filterToParameterTransformer, _consumerFieldNames);
string[] _providerFieldNames = new string[1];
_providerFieldNames[0] = providerFieldName;
FieldInfo prvFld = typeof(TransformableFilterValuesToParametersTransformer).GetField("_providerFieldNames", BindingFlags.Instance | BindingFlags.NonPublic);
prvFld.SetValue(filterToParameterTransformer, _providerFieldNames);
}
catch
{
throw new Exception("Unexpected internal definition for 'TransformableFilterValuesToParametersTransformer'. Please amend private member access code.");
}
return filterToParameterTransformer;
}
现在创建连接:
TransformableFilterValuesToParametersTransformer transformer = CreateTransformer("ConsumerFieldInternalName", "ProviderFieldInternalName");
ProviderConnectionPointCollection pcpc = mgr.GetProviderConnectionPoints(providerWebPart);
ConsumerConnectionPointCollection ccpc = mgr.GetConsumerConnectionPoints(consumerWebPart);
mgr.SPConnectWebParts(
providerWebPart, pcpc[0],
consumerWebPart,
ccpc[0],
transformer
);
mgr是特定视图页面的SPLimitedWebPartManager实例。
您可以在此处找到更多示例: