【问题标题】:Web Part connections in site definitions网站定义中的 Web 部件连接
【发布时间】:2010-11-06 03:09:21
【问题描述】:

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

【问题讨论】:

    标签: sharepoint web-parts site-definition


    【解决方案1】:

    去年的某个时候我也碰到过这个问题!看起来无法再以新的 .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");
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      我将通过实现“OnActivated”事件处理程序在 SiteProvisioning-Feature 中配置 WebPart。这样,代码将在创建网站时运行,您可以按照自己喜欢的方式处理错误(即,如果 WebPart 在创建网站时不可用 - 无论出于何种原因)

      我希望这会有所帮助!

      【讨论】:

      • 这是在站点定义中提供 Web 部件连接的唯一方法吗?我不能只在 onet.xml 中指定 webpart 连接属性吗?我认为在 sharepoint 2003 中有两个 web 部件属性有“connectionid”和“connections”。我不能使用相同的吗?如果是怎么办?
      【解决方案3】:

      您需要使用 标记来声明您的 Web 部件,然后在封闭的 元素中声明您的连接。

      example

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-22
        • 2010-09-19
        • 2011-05-24
        • 1970-01-01
        • 2011-08-01
        • 1970-01-01
        • 2011-02-01
        • 2010-09-17
        相关资源
        最近更新 更多