Matthew Knott

Previous: Filipo Levi
Next: Setting Page Content In SharePoint 2007 Programattically, And It's Drawbacks

Moving A SharePoint Publishing Page To Another Site Collection - Part 2

Posted 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.


  • Updates on Moving Pages????????, posted by Sachin Sapkale

    Were you able to move the page from one site to another at last?

  • Nearly, posted by Matt

    Hi Sachin,

    I've managed to move master files and page templates without problem. I've got an idea about doing it, but the approach I eventually took was to create a profile for a page and create it based on a profile, create the page and set the template, then add the webparts to the relevant zones (ensuring they're active).

    I'll try an idea I've got on Monday but I'm sure it doesn't work, but if I can get anywhere I'll let you know.

  • I'm in, posted by Mohammed

    I'm going to try it :)

  • Same reuriment doing, posted by venkat


    I am also looking for same requirment,but can send me sample code for this.


  • Answer my prayers?, posted by Shannon

    Hey Matt,

    Did you end up getting this to work in the end?

    I am facing this problem at the moment and it is killing me.

    I am praying you have succeeded and you can guide me or if there is some sample code.


  • Sorry, posted by Matt

    Hi Shannon,

    Unfortunately not, I tried everything.

Add a comment