Friday, March 16, 2018

I had a requirement to move root level site collection as a subsite, as everyone knows this can be done by using the Granular back up for the site, you need to take .cmp file,
I tried to restore the site to a sub site, i was unable to import it as the site template for the destination site is not matching with the backup file which i took,
i.e. The back up which i took is BLANKINTERNET#0 web template, and i created a blank site wanted to override this site, i.e. STS#1, then again i tried to create a publishing site as the source was the publishing site, again this did not work, becouse  destination was CMSINTERENET#1 site,
the best solution is to create site of source site, i wrote a power shell script to achieve this,

1: # Get-SPWebTemplate
   2: #$template = Get-SPWebTemplate "blankinternet#0"
   3: #New-SPWeb -Url "http://dca-dev-230:6565/sites/guru/gwp/" -Template $template 

this is create a destination site which you want, 
then try to import your site, it works well !
after that I had a custom layout which is designed by SPD, as it was a root level collection, something goes wrong no pages which use the custom layout is not working,
because publishing site is not recommended to import and export, Microsoft disables this for publishing site, but still we want to do sometimes. Smile

Steps to work your all layouts pages

1) create a testing page and apply your layout to that page, download this file and check what is the proper name of the <publishinglayout> tag,

   1: http://<site url>/sites/guru/_catalogs/masterpage/GWP_BlankWebPartPage.aspx, /sites/guru/_catalogs/masterpage/GWP_BlankWebPartPage.aspx

this you need to copy and run my below, script.
boring to do for all the pages? Sad smile
run below script




$web = Get-SPWeb -Identity "http://<site url>/sites/guru/gwp/";


$spPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web);

$pages = $spPubWeb.PagesList;


foreach($item in $pages.Items)


  $pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)


  $url = new-object Microsoft.SharePoint.SPFieldUrlValue($pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout].ToString())

  if($url -ne $null)


    if($url.Url -match 'GWP_BlankWebPartPage') #layout name


  $newurl = new-object Microsoft.SharePoint.SPFieldUrlValue("http:/<site url>/sites/guru/_catalogs/masterpage/GWP_BlankWebPartPage.aspx, /sites/guru/_catalogs/masterpage/GWP_BlankWebPartPage.aspx")



  $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = $newurl



  $pubPage.ListItem.File.CheckIn("Fixed URL to page layout.", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);


No comments:

Post a Comment