Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello everybody.

I am trying to create a regular web part page with powershell and I am not able to do it. There is no information in google about the error I get:
PHP
$spWeb = Get-SPWeb -Identity "http://server/site"
$pubWeb =[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
$pl = $pubWeb.GetAvailablePageLayouts()

Exception calling "GetAvailablePageLayouts" with "0" argument(s): "Object reference not set to an instance of an object."
At line:1 char:38
C#
+ $pl = $pubWeb.GetAvailablePageLayouts <<<< ()
    + CategoryInfo          : NotSpecified: (: ) [ ], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

The error occurs when executing GetAvailablePageLayouts().

Any clue? Thank you.
Posted
Updated 22-Jan-13 5:16am
v2
Comments
Sandeep Mewara 22-Jan-13 11:18am    
Does this expect parameters: GetAvailablePageLayouts ?

is #pubWeb not null? Debug and see.
garfield185 22-Jan-13 11:20am    
Can have, or not any parameters. Should work without any paramenters.
And, after doing $pubweb I receive

IsAllowingAllWebTemplates : True
IsAllowingAllPageLayouts : True
IsInheritingAvailableWebTemplates : False
IsInheritingAvailablePageLayouts : False
IsInheritingDefaultPageLayout : False
IsInheritingNewPageUrlToken : False
DefaultPageLayout :
NewPageUrlToken : NewPage
Web : Home
IsRoot : False
....

So I can confirm it is not null.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900