1

I created custom html page layout with embedded web part in it. When I am trying to add page to pages library by powershell getting below error

Fail: Exception calling "AddPublishingPage" with "2" argument(s): "No parameterless constructor defined for this object."

at $Page = $PubWeb.AddPublishingPage($PageName, $PageLayout)

Strange part is. When I create page manually with same page layout its getting created and once I create it manually. My Script is working fine. I can create pages withouts error once I create page manually.

Not sure what is happning here

Script below :

     $PageTitle = $newPage.NewPageTitle
     $Layouts = $PubSite.GetPageLayouts($False)
         foreach($layout in $Layouts){
             if($layout.Name -eq $PageLayoutRelUrl){
                 $PageLayout = $layout
             }
         }
    $Page = $PubWeb.AddPublishingPage($PageName, $PageLayout)
    $Page.Title = $PageTitle
    $Page.Update();
    $Page.CheckIn("Deployment CheckIn")
    $Page.ListItem.File.Publish("Deplyment Pulish")
  • Please post your current script! – Mohamed El-Qassas MVP Oct 10 '17 at 20:28
  • Added part of script which actually create page and takes page layout. – Bhaskar Dhone Oct 10 '17 at 20:35
0

In your script, you have defined the $PageLayout but you didn't define the $PageName so you got this error

Fail: Exception calling "AddPublishingPage" with "2" argument(s): "No parameterless constructor defined for this object."

Try to define the $PageName as the following

 $PageName = "Test.aspx"

Then use it at

$Page = $PubWeb.AddPublishingPage($PageName, $PageLayout)
| improve this answer | |
  • I added part of script. $pageName has value coming similar as "Test.aspx". If you notice strange part with same script I am able to create pages if first create manually with that page layout in Pages library. – Bhaskar Dhone Oct 10 '17 at 20:45

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.