0

I want to modify the layout of my page Index.aspx.

I adapt the html code with my change and i deploy the change on my sharepoint server. The problem was, i cannot the change. There was only the old page layout.

On a forum i found a code that can "apply" the change but the code crashed my application.

$spWeb = Get-SPWeb("mywebsite")
$spFile = $spWeb.GetFile("mywebsite/Pages/Index.aspx") 
$spFile.CheckOut("Online",$null) 
$spFile.Properties["PublishingPageLayout"] = "/_catalogs/masterpage/Pages/Index.aspx, Index" 
$spFile.Update() 
$spFile.CheckIn("Update page layout via PowerShell",[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn) 
$spWeb.Dispose()

How can i rollback the change ?

0

This post has a slightly different method for changing the page layout that might work for you: http://myspworld.wordpress.com/2012/08/16/powershell-script-to-change-the-page-layout/

$spWeb = Get-SPWeb("http://yourwebapplication.com/yoursite")
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
$pSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($spWeb.Site);

$siteLayouts = $pSite.GetPageLayouts($false)
$myLayout = $siteLayouts["/_catalogs/masterpage/yourpagelayout.aspx"]
#$myLayout
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='RecursiveAll'"

$pages = $pWeb.GetPublishingPages($query)

foreach ($page in $pages)
{
    if ($page.ContentType.Name -eq "Folder")
    {
        continue
    }

    $page.Layout = $myLayout
    $page.update()
    $page.ListItem.File.Publish("")
    $page.ListItem.File.Approve("")
}
$spWeb.Dispose()
  • It work. I can see my Index.aspx page ! – Sancho May 21 '14 at 14:38

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.