Moving A SharePoint Publishing Page To Another Site Collection - Part 2Posted on Thursday, 19 February 2009 09:16
Okay, no code for you yet but I'm achingly close, I will, however take you through how it's going to work, I'm just getting some silly errors right now.
Step 1: Get the source information
Firstly, establish an SPSite & SPWeb class object for the source site. Create:
- An SPFile from the Pages List item you want to copy (Listitem.File)
- A PublishingWeb for the current web
- A PublishingPage for the source file
- A PageLayout for the source files PublishingPage.Layout
- An SPLimitedWebPartManager for the source SPFile
- An SPLimitedWebPartCollection for the SPLimited webpart manager.
Once you've done that, create a new SPSite and SPWeb for the destination.
Create a New PublishingWeb, and within there a new PublishingFile with the same name as the source publishing file.
Give the file the layout of the source file. The most robust way to do this is to create a PageLayout array based on the target web, and then get the publishing layout id where the titles match.
Once you have the layout set, now set the title and the description.
Next is the tricky part, replicating the page elements.
Let me just say, I threw everything at this and had to stop in the end just to get some fresh eyes back and look another day, but I've tried exporting the webparts one by one, just creating Webpart objects from the source and adding them to the target page, nothing seemed to work.
My target way of doing this will be to loop the webparts from the source page, get a webpart catalog, match them, add the webpart, set the properties to that of the source and move on.
Finally check the file in and publish.
I'm nearly there, it's just the webparts and lists that are a problem, hopefully it'll be cracked before too long.