The Manage Content and Structure tool in Publishing Sites has a move command, 
and it seems to move an Page across to a new SPWeb and preserves version 
history of the page and meta data.

Microsoft.SharePoint.Publishing.Internal.WebControls.MoveItems is an internal 
class that is used by the manage content and structure tool to move pages 
between spwebs

Loading this class into reflector, it seems that the code first copies across 
the item to the destination first, then checks if the copy was successful, it 
then deletes the source item.

How is the copy done?
DeploymentWrapper wrapper = new DeploymentWrapper(base.Site);
wrapper.PrimeExportProgressUpdated += new 
DeploymentWrapper.ExportProgressUpdatedCallBackHandler(this.deploymentWrapper_PrimeExportProgressUpdated);
      wrapper.PrimeCallBack += new 
DeploymentWrapper.ImportCallBackEventHandler(this.deploymentWrapper_PrimeCallBack);
      wrapper.PrimeImportError += new 
DeploymentWrapper.ImportErrorCallBackHandler(this.deploymentWrapper_PrimeImportError);
      objectSerializer = ObjectSerializer.GetObjectSerializer(base.Site, 
this.destinationid);
      string str = Convert.ToString(this.sourceSmtObjectIds.Length, 
CultureInfo.InvariantCulture);
      base.StatusDescription = 
Resources.GetFormattedString("SmtMoveWrapperStart", new object[] { str });
      base.UpdateStatus();
      wrapper.MoveItems(this.sourceSmtObjectIds, this.destSmtObjectId);
      this.isMoveItemsOutOfSomeVariationHierarchy = 
wrapper.IsMoveItemsOutOfSomeVariationHierarchy;

SPExportSettings exportSettings = new SPExportSettings();
        this.configureExportCopyOrMove(sourceSmtObjectIds, ref exportSettings, 
SPIncludeVersions.All);
        export = new SPExport(exportSettings);
        export.ProgressUpdated += new 
EventHandler<SPDeploymentEventArgs>(this.export_ProgressUpdated);
        export.Run();
        SPImportSettings importSettings = new SPImportSettings();
        this.copyDestSmtObject = 
ObjectSerializer.GetObjectSerializer(this.site, destSmtObjectId);
        this.configureImportCopyOrMove(exportSettings, ref importSettings);
        SPImport import = new SPImport(importSettings);
        this.copyOrMoveRequiresVariationsCleanup = 
this.CheckIsMoveItemsOutOfSomeVariationHierarchy(sourceSmtObjectIds, 
destSmtObjectId);
        import.ObjectImported += new 
EventHandler<SPObjectImportedEventArgs>(this.import_ObjectImported);
        import.Started += new 
EventHandler<SPDeploymentEventArgs>(this.importStarted_CopyOrMove);
        import.Error += new 
EventHandler<SPDeploymentErrorEventArgs>(this.import_Error);
        import.Run();

The code uses more Internal Classes L, looks like the PRIME API (Content 
Deployment) is used to do the copy, which explains how the Versioning and 
History is preserved with the move, just like content deployment between 
servers in a Farm.

On top of that it seems the code also fixes inbound links to the original page, 
so links to the old page location throughout the MOSS site are updated, and now 
point to the new page location.

Would be so much nicer if this wasn't an internal class, we could then use this 
class in our code.  What compounds this further is the Internal Class further 
uses MORE Internal Classes... So I don't see a way we could reproduce this same 
functionality with our own custom code, thanks for tying our hands like this 
Microsoft!

>> find a proper way to programmatically do a supposing simple task like moving 
>> a page (list item).

Microsoft did develop a way to do this, but they don't want anyone else to 
re-use their internal class. Seems silly to me because as Wilson mentions this 
is a simple task we would all expect would be easy and standard to develop.

Sezai Kömür
Senior Developer  - BEng, BSc - Microsoft Certified Technology Specialist  -  
http://www.moss2007.com.au/

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of WAMPERS Wilson 
(Con)
Sent: Thursday, 29 November 2007 2:10 PM
To: [email protected]
Subject: [OzMOSS] Moving pages programmatically within a web -> sub web whilst 
maintaining versioning

Hi All,

I wonder if someone can give me some recommendations on which method to 'best' 
use moving a (publishing) page from a web to a sub-web programmatically, in a 
way that the page's versioning can be kept? (all on the same farm, even using 
the same master page, content type ...)
I've tried:

·         Using SPFile.moveto to move it to a document folder and then use 
redirection pages to point to it .. gives metadata issues. (Don't like 
workaround solutions in the first place)

·         Using SPExport, SPImport (Microsoft.SharePoint.Deployment) and 
different settings of it, but still 'metadata missing' issues remain either 
when the moved page is opened or when looking at it going 'edit toolbar' Page 
-> Page Settings and Schedule.

I managed to get custom timer jobs going (thx Andrew Connell) etc... But I find 
it very difficult to find a proper way to programmatically do a supposing 
simple task like moving a page (list item).
If somebody can point me in the right direction that'll be very much 
appreciated, thank you.

Kind Regards,

Wilson Wampers









------------------------------------------------------------------- OzMOSS.com 
- to unsubscribe from this list, send a message back to the list with 
'unsubscribe' as the subject.
Powered by mailenable.com - List managed by www.readify.net



------------------------------------------------------------------- OzMOSS.com 
- to unsubscribe from this list, send a message back to the list with 
'unsubscribe' as the subject.

Powered by mailenable.com - List managed by www.readify.net

Reply via email to