我要求在onet.xml中指定web部件连接。因此,当使用此站点定义创建站点时,所述web部件已连接并可供使用。我需要为onet.xml中的特定web部件指定哪些属性。
发布于 2009-06-26 20:46:58
我也在去年的某个时候碰到过这个问题!看起来不能再像在旧的.dwp格式中那样在新的.webpart格式的Web部件上指定连接了。我最终在网站定义中加入了一个自定义功能,就像kpinhack也建议的那样。下面列出了用于连接Web部件的代码。该方法只是为连接两个不同类型的Web部件而设计的,它不支持在同一页面上有多个相同类型的Web部件。但我相信你会领会大意的。
private void ConnectWebParts(SPWeb web, string pageName, Type providerType, Type consumerType)
{
SPFile file = web.GetFile(pageName);
SPList list = null;
if (file.InDocumentLibrary)
{
list = file.Item.ParentList;
if (list.ForceCheckout) file.CheckOut();
}
SPLimitedWebPartManager webPartManager =
web.GetLimitedWebPartManager(
pageName,
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
WebPart provider = null;
foreach (WebPart wp in webPartManager.WebParts)
{
if (wp.GetType() == providerType)
{
provider = wp;
break;
}
}
foreach (WebPart consumer in webPartManager.WebParts)
{
if (consumer.GetType() != consumerType) continue;
ProviderConnectionPointCollection providerConnections = webPartManager.GetProviderConnectionPoints(provider);
ProviderConnectionPoint providerConnection = providerConnections[0];
ConsumerConnectionPointCollection consumerConnections = webPartManager.GetConsumerConnectionPoints(consumer);
ConsumerConnectionPoint consumerConnection = consumerConnections[0];
SPWebPartConnection con = webPartManager.SPConnectWebParts(provider, providerConnection, consumer, consumerConnection);
webPartManager.SPWebPartConnections.Add(con);
}
if (list != null)
{
if (list.ForceCheckout)
{
file.CheckIn("Added Web Part Connections");
}
if (list.EnableVersioning && list.EnableMinorVersions)
{
file.Publish("Added Web Part Connections");
}
}
}发布于 2009-06-26 12:33:43
我会在SiteProvisioning-Feature中配置WebParts,方法是实现“OnActivated”-Eventhandler。这样,代码将在网站创建时运行,您可以按自己喜欢的方式处理错误(例如,如果WebParts在网站创建时不可用-无论出于什么原因)
我希望这能帮到你!
发布于 2009-06-26 21:08:45
您需要使用< AllUsersWebPart >标记来声明您的web部件,然后在包含的< WebPart >元素中声明您的连接。
example
https://stackoverflow.com/questions/1048736
复制相似问题