2

I want to add a new developed WebPart to a SharePoint site with PowerShell.

How it is possible to add the WebPart reference from my WebPart to the PowerShell script?

$web = Get-SPWeb $urlWeb

$webpartmanager=$web.GetLimitedWebPartManager($urlWebWP,  [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

$webpart = new-object  ReferenceToMyWebPartProblem

$webpartmanager.AddWebPart($webpart, $webpartzone, $index);
2

Here is a link to a page that describes the process for the out of the box SharePoint webparts. If you want to include your own webpart, you need to add a reference to your assembly in powershell. The following line adds a reference to one of my custom webparts into powershell.

 [System.Reflection.Assembly]::Load("rossri.NavigationControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a60d1a662835ad70")

Once the reference is added, I can then create a new object of the type of my custom webpart. For fun I changed the title and then added it using the webpartmanager object.

$webpart = New-Object rossri.NavigationControl.UserListViewPart.UserListViewPart
$webpart.Title = "NewPart from Powershell"
$webpartmanager.AddWebPart($webpart, "Left", "0")

I checked the page and it was added to the zone I defined.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.