Adding visual webpart to list display form

Copper Contributor

I am working on creating a template for my SharePoint 2013 site, using PNP powershell.  One of the requests is to create a custom list and add a custom visual webpart to the display form.

 

I am using:

Add-PnPWebPartToWebPartPage -ServerRelativePageUrl "/extranet/anotherxcjlc/lists/pleadings/dispform.aspx" -Path
"E:\scripts\pnpSite\MLBDocumentUploader.webpart" -ZoneId 'Main' -ZoneIndex 2
 
I tried exporting the webpart from the display form and then adding it:
Add-PnPWebPartToWebPartPage : Cannot import this Web Part.
 
I also tried downloading it from the webpart gallery and adding it:
Add-PnPWebPartToWebPartPage : The operation could not be completed because the Web Part is not on this page.
 
What procedure should I use to add this webpart to my display forms?
 
Thank you.
2 Replies

HI @Sergei Gorelik,

 

I think the issue that you are running into is similar to one I had a while back.

 

In my case a view on a list was set to the default welcome page when I exported the site and PnP PowerShell wasn't able to handle the web parts on the page as the page used isn't a web part page but a view on a list.

 

I wouldn't be surpised if you have the same issue as you are using Add-PnPWebPartToWebPartPage to add a web part to a page that isn't a web part page. You could probably add a new page and add a list view web part and then add your custom web parts to that page.

 

 

Hi @Pieter Veenstra

 

Thank you for your feedback, I actually tried adding it to the webpart only page with the same errors.  I am thinking that add-webpart commandlet is not able to handle custom visual webparts.