gpt4 book ai didi

sharepoint - 网站定义中的 Web 部件连接

转载 作者:行者123 更新时间:2023-12-04 15:38:03 25 4
gpt4 key购买 nike

我需要在 onet.xml 中指定 Web 部件连接。因此,当使用此站点定义创建站点时,所述 Web 部件已经连接并可以使用。我需要为 onet.xml 中的特定 Web 部件指定哪些属性。

最佳答案

去年的某个时候我也撞到了这个墙上!看起来连接不能再以新的 .webpart 格式在 Web 部件上指定,因为它们可以在旧的 .dwp 格式中指定。我最终在站点定义中包含了一个自定义功能,如 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");
}
}
}

关于sharepoint - 网站定义中的 Web 部件连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1048736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com