Guest User

Untitled

a guest
Feb 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. $wpConnection = $webpartmanager.SPConnectWebParts($wpProvider, $providerConnectionPoint, $wpConsumer, $consumerConnectionPoint, $transformer)
  2.  
  3. $web = Get-SPWeb ($siteurl)
  4. $list = $web.Lists["Web Part Gallery"]
  5. $wpManager = $web.GetLimitedWebPartManager($web.Url + "pages/pagename.aspx",[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared);
  6. $wpl = $list.Items | where {$_.Title -eq "Your Webpart Name"}
  7. $xmlReader = New-Object System.Xml.XmlTextReader($wpl.File.OpenBinaryStream());
  8. $errorMsg = ""
  9. $webPart = $wpManager.ImportWebPart($xmlReader, [ref]$errorMsg)
  10. $wpManager.AddWebPart($webpart,"Header",1)
  11. $wp2 = $wpManager.WebParts | Where {$_.Title -eq "LeftMarginFilterWebPart"}
  12. $conWP = $wpManager.GetConsumerConnectionPoints($webpart)[0]
  13. $provWP = $wpManager.GetProviderConnectionPoints($wp2)[0]
  14. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  15. #if these are ootb web parts you need to set the trans up and call the overloaded SPConnectWebParts with $trans as the last param
  16. #$trans = New-Object Microsoft.SharePoint.WebPartPages.SPRowToParametersTransformer
  17. #trans.ConsumerFieldNames = new string[] {"Category"};
  18. #trans.ProviderFieldNames = new string[] {"Title"};
  19. $newCon = $wpManager.SPConnectWebParts($wp2,$provWP,$webPart,$conWP)
  20. $wpManager.SPWebPartConnections.Add($newCon);
  21. $wpManager.Dispose()
  22. $web.Dispose()
Add Comment
Please, Sign In to add comment