private static void ConnectWebParts(SPLimitedWebPartManager _pageMgr, WebPart _prvdr, WebPart _cnsmr, string _providerConnectionPoints, string _consumerConnectionPoints)
 {
     _pageMgr.SPConnectWebParts(
         _prvdr,
         _pageMgr.GetProviderConnectionPoints(_prvdr)[_providerConnectionPoints],
         _cnsmr,
         _pageMgr.GetConsumerConnectionPoints(_cnsmr)[_consumerConnectionPoints]);
 }
示例#2
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite siteCollection = (SPSite)properties.Feature.Parent;
            SPWeb  site           = siteCollection.RootWeb;

            // create dropdown menu for custom site pages
            SPNavigationNodeCollection topNav = site.Navigation.TopNavigationBar;

            SPNavigationNode DropDownMenu1 =
                topNav.AddAsLast(new SPNavigationNode("Web Parts 101", ""));

            DropDownMenu1.Children.AddAsLast(new SPNavigationNode("Web Part 1", "WebPartPages/WebPart1.aspx"));
            DropDownMenu1.Children.AddAsLast(new SPNavigationNode("Web Part 2", "WebPartPages/WebPart2.aspx"));
            DropDownMenu1.Children.AddAsLast(new SPNavigationNode("Web Part 3", "WebPartPages/WebPart3.aspx"));
            DropDownMenu1.Children.AddAsLast(new SPNavigationNode("Web Part 4", "WebPartPages/WebPart4.aspx"));
            DropDownMenu1.Children.AddAsLast(new SPNavigationNode("Web Part 5", "WebPartPages/WebPart5.aspx"));

            SPNavigationNode DropDownMenu2 =
                topNav.AddAsLast(new SPNavigationNode("Web Part Samples", ""));

            DropDownMenu2.Children.AddAsLast(new SPNavigationNode("Custom Properties", "WebPartPages/CustomProperties.aspx"));
            DropDownMenu2.Children.AddAsLast(new SPNavigationNode("Web Part Verbs", "WebPartPages/WebPartVerbs.aspx"));
            DropDownMenu2.Children.AddAsLast(new SPNavigationNode("Web Part Connections", "WebPartPages/WebPartConnections.aspx"));
            DropDownMenu2.Children.AddAsLast(new SPNavigationNode("Web Parts Preconnected", "WebPartPages/WebPartsPreconnected.aspx"));
            DropDownMenu2.Children.AddAsLast(new SPNavigationNode("Async Web Part Demo", "WebPartPages/AsyncDemoWebPart.aspx"));


            SPFile page = site.GetFile("WebPartPages/WebPartsPreconnected.aspx");
            SPLimitedWebPartManager mgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared);

            FontConnectionProvider.FontConnectionProvider ProviderWebPart = new FontConnectionProvider.FontConnectionProvider();
            ProviderWebPart.Title         = "Left Brain";
            ProviderWebPart.UserGreeting  = "I look pretty";
            ProviderWebPart.TextFontSize  = 18;
            ProviderWebPart.TextFontColor = "Green";
            mgr.AddWebPart(ProviderWebPart, "Left", 0);

            FontConnectionConsumer.FontConnectionConsumer ConsumerWebPart = new FontConnectionConsumer.FontConnectionConsumer();
            ConsumerWebPart.Title        = "Right Brain";
            ConsumerWebPart.UserGreeting = "And so do I";
            mgr.AddWebPart(ConsumerWebPart, "Right", 0);

            mgr.SPConnectWebParts(
                ProviderWebPart,
                mgr.GetProviderConnectionPoints(ProviderWebPart).Default,
                ConsumerWebPart,
                mgr.GetConsumerConnectionPoints(ConsumerWebPart).Default
                );
        }
        public static void ConnectWebPartConsumersToReportFilter(SPLimitedWebPartManager webPartManager)
        {
            // Get the report filter provider.
            var providerWebPart = webPartManager
                                  .WebParts
                                  .Cast <WebPart>()
                                  .FirstOrDefault(e => e.GetType().ToString() == "EPMLiveWebParts.ReportingFilter");

            if (providerWebPart == null)
            {
                return;
            }

            ProviderConnectionPoint providerConnection = null;

            foreach (ProviderConnectionPoint point in webPartManager.GetProviderConnectionPoints(providerWebPart))
            {
                if (point.InterfaceType == typeof(IReportID))
                {
                    providerConnection = point;
                    break;
                }
            }

            // Run through each consumer and connect them to the report filter.
            foreach (Microsoft.SharePoint.WebPartPages.WebPart webPart in webPartManager.WebParts)
            {
                if (webPart == providerWebPart)
                {
                    continue;
                }

                foreach (ConsumerConnectionPoint point in webPartManager.GetConsumerConnectionPoints(webPart))
                {
                    if (point.InterfaceType == typeof(IReportID))
                    {
                        webPartManager.SPConnectWebParts(providerWebPart, providerConnection, webPart, point);

                        break;
                    }
                }
            }
        }
        public static void AddWebPartConnectionAspNet(
            SPWeb web,
            string pageUrl,
            string providerWebPartID,
            string consumerWebPartID,
            string providerConnectionPointName,
            string consumerConnectionPointName)
        {
            using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared)) {
                WebPart provider = manager.WebParts [providerWebPartID];
                WebPart consumer = manager.WebParts [consumerWebPartID];

                ProviderConnectionPointCollection providerPoints = manager.GetProviderConnectionPoints(provider);
                ConsumerConnectionPointCollection consumerPoints = manager.GetConsumerConnectionPoints(consumer);

                ProviderConnectionPoint providerPoint = null;

                foreach (ProviderConnectionPoint point in providerPoints)
                {
                    if (String.Equals(providerConnectionPointName, point.DisplayName, StringComparison.OrdinalIgnoreCase))
                    {
                        providerPoint = point;
                        break;
                    }
                }

                ConsumerConnectionPoint consumerPoint = null;

                foreach (ConsumerConnectionPoint point in consumerPoints)
                {
                    if (String.Equals(consumerConnectionPointName, point.DisplayName, StringComparison.OrdinalIgnoreCase))
                    {
                        consumerPoint = point;
                        break;
                    }
                }

                manager.SPConnectWebParts(provider, providerPoint, consumer, consumerPoint);
            }
        }
        private static void ConnectWebParts(SPFeatureReceiverProperties properties, string url, System.Web.UI.WebControls.WebParts.WebPart provider,
                                            System.Web.UI.WebControls.WebParts.WebPart[] consumer)
        {
            SPWeb  web  = (SPWeb)properties.Feature.Parent;
            SPFile file = web.GetFile(url);
            SPLimitedWebPartManager manager       = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
            ProviderConnectionPoint providerPoint = null;
            ConsumerConnectionPoint consumerPoint = null;
            int index = 6;

            while (manager.WebParts.Count > 0)
            {
                manager.DeleteWebPart(manager.WebParts[0]);
            }

            manager.AddWebPart(consumer[0], "MiddleColumn", 2);
            manager.AddWebPart(provider, "MiddleColumn", 4);

            for (int i = 1; i < consumer.Length; i++)
            {
                System.Web.UI.WebControls.WebParts.WebPart webpart = consumer[i];

                manager.AddWebPart(webpart, "MiddleColumn", index);
                index += 2;
            }

            providerPoint = manager.GetProviderConnectionPoints(provider)[0];
            consumerPoint = manager.GetConsumerConnectionPoints(consumer[0])[0];
            manager.SPConnectWebParts(provider, providerPoint, consumer[0], consumerPoint);
            file.Update();

            if (manager.Web != null)
            {
                manager.Web.Dispose();
            }

            manager.Dispose();
        }
        public static void ConnectListViewWebParts(SPLimitedWebPartManager webPartManager, ListViewWebPart providerWebPart, ListViewWebPart consumerWebPart, SPRowToParametersTransformer transformer, string consumerInternalFieldName, string providerInternalFieldName)
        {
            webPartManager.RequireNotNull("webPartManager");
            providerWebPart.RequireNotNull("providerWebPart");
            consumerWebPart.RequireNotNull("consumerWebPart");
            transformer.RequireNotNull("transformer");
            consumerInternalFieldName.RequireNotNullOrEmpty("consumerInternalFieldName");
            providerInternalFieldName.RequireNotNullOrEmpty("providerInternalFieldName");

            ProviderConnectionPoint providerConnectionPoint = (from ProviderConnectionPoint conn in webPartManager.GetProviderConnectionPoints(providerWebPart)
                                                               where String.Equals("Provide Row To", conn.DisplayName, StringComparison.OrdinalIgnoreCase) && conn.InterfaceType == typeof(IWebPartRow)
                                                               select conn).FirstOrDefault();
            ConsumerConnectionPoint consumerConnectionPoint = (from ConsumerConnectionPoint conn in webPartManager.GetConsumerConnectionPoints(consumerWebPart)
                                                               where String.Equals("Get Sort/Filter From", conn.DisplayName, StringComparison.OrdinalIgnoreCase) && conn.InterfaceType == typeof(IWebPartParameters)
                                                               select conn).FirstOrDefault();

            consumerWebPart.Connections = consumerWebPart.ConnectionID + "," + providerWebPart.ConnectionID + "," +
                                             consumerConnectionPoint.ID + "," + providerConnectionPoint.ID + "," +
                                             consumerConnectionPoint.ID + "," + providerConnectionPoint.ID + "," +
                                              consumerInternalFieldName + "=" + providerInternalFieldName;

            webPartManager.SaveChanges(consumerWebPart);
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;

            if (web != null)
            {
                SPFile file = web.GetFile("Category.aspx");
                if (file.Exists)
                {
                    SPLimitedWebPartManager manager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);

                    System.Web.UI.WebControls.WebParts.WebPart bdcItemBuilder         = null;
                    System.Web.UI.WebControls.WebParts.WebPart categoryDetails        = null;
                    System.Web.UI.WebControls.WebParts.WebPart childCategoriesWebPart = null;
                    System.Web.UI.WebControls.WebParts.WebPart productsWebPart        = null;

                    foreach (System.Web.UI.WebControls.WebParts.WebPart webPart in manager.WebParts)
                    {
                        switch (webPart.Title)
                        {
                        case "Business Data Item Builder":
                            bdcItemBuilder = webPart;
                            break;

                        case "Category Details":
                            categoryDetails = webPart;
                            break;

                        case "Category List":
                            childCategoriesWebPart = webPart;
                            break;

                        case "Product List":
                            productsWebPart = webPart;
                            break;
                        }
                    }

                    ProviderConnectionPoint providerConnection = manager.GetProviderConnectionPoints(bdcItemBuilder)[0];
                    ConsumerConnectionPoint consumerConnection = manager.GetConsumerConnectionPoints(childCategoriesWebPart)[0];
                    SPWebPartConnection     connection         = manager.SPConnectWebParts(bdcItemBuilder, providerConnection, childCategoriesWebPart, consumerConnection);
                    manager.SPWebPartConnections.Add(connection);

                    consumerConnection = manager.GetConsumerConnectionPoints(productsWebPart)[0];
                    connection         = manager.SPConnectWebParts(bdcItemBuilder, providerConnection, productsWebPart, consumerConnection);
                    manager.SPWebPartConnections.Add(connection);

                    consumerConnection = manager.GetConsumerConnectionPoints(categoryDetails)[0];
                    connection         = manager.SPConnectWebParts(bdcItemBuilder, providerConnection, categoryDetails, consumerConnection);
                    manager.SPWebPartConnections.Add(connection);

                    manager.Web.Dispose();
                }

                web.Site.WebApplication.WebConfigModifications.Add(sPWebConfigModification);

                //Call Update and ApplyWebConfigModifications to save changes
                web.Site.WebApplication.Update();
                web.Site.WebApplication.WebService.ApplyWebConfigModifications();
            }
        }