Welcome to TechNet Blogs Sign in | Join | Help

Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

[Part 1 - Part 2 - Part 3 - Part 4 - Part 5 - Part 6]

Advanced content deployment scenarios

Till now we have covered export and import of

  • single list items or documents
  • containers like folders, lists or webs
  • complete site collection

What we haven't covered is how to use this method to move items. Or how to control the which items from the export package need to get imported into the database.

Let's look on each of these topics separately.


1) Moving content using Content Deployment and Migration API

Export and import allows us to create a copy of items or containers but it does not automatically allow us to move content. But copying the content and then deleting the original content is very similar to a real move operation. the only problem here is that links pointing to the moved content will still point to the original content. So these would have to be adjusted.

And this is indeed what the Move operation in Site Manager does! It copies the content using the Content Deployment and Migration API, adjusts all links to point to the new content and then delete the original content.

Let's now look on a sample how this can be achieved by looking at a sample code for the move of a single image from an image library.

First step is to export the ListItem using the Content Deployment and Migration API as demonstrated in part 2:

// export an image from the Images Library

SPSite site = new SPSite("http://localhost:2000");
SPWeb web = site.OpenWeb("/SourceSubWeb");
SPList list = web.Lists["Images"];
SPListItem listItem = list.Items[0];

SPExportObject exportObject = new SPExportObject();
exportObject.Id = listItem.UniqueId;
exportObject.Type = SPDeploymentObjectType.ListItem;

SPExportSettings exportSettings = new SPExportSettings();
exportSettings.ExportObjects.Add(exportObject);
exportSettings.FileLocation = @"c:\export";
exportSettings.FileCompression = false;
exportSettings.SiteUrl = "http://localhost:2000";

SPExport export = new SPExport(exportSettings);
export.Run();

// cleanup
web.Dispose();
site.Dispose();

The next step is to import the image from the export into a the desired new location similar to the steps described in part 3:

// import the image into the desired destination library

SPImportSettings importSettings = new SPImportSettings();
importSettings.SiteUrl = "http://localhost:2000";
importSettings.FileLocation = @"c:\export";
importSettings.FileCompression = false;
importSettings.RetainObjectIdentity = false;

SPImport import = new SPImport(importSettings);

EventHandler<SPDeploymentEventArgs> startedEventHandler = new EventHandler<SPDeploymentEventArgs>(OnStarted);
import.Started += startedEventHandler;

EventHandler<SPObjectImportedEventArgs> importedEventHandler = new EventHandler<SPObjectImportedEventArgs>(OnImported);
import.ObjectImported += importedEventHandler;

import.Run();

...

// event handler to assign a new parent to the orphaned image in the package

static
 void OnStarted(object sender, SPDeploymentEventArgs args)
{
   SPSite site = new SPSite("http://localhost:2000");
   SPWeb web = site.OpenWeb("/MyWeb");
   SPList list = web.Lists["Images"];

   SPImportObjectCollection rootObjects = args.RootObjects;
   foreach (SPImportObject io in rootObjects)
   {
      io.TargetParentUrl = list.RootFolder.ServerRelativeUrl;
   }

   web.Dispose();
   site.Dispose(); 
}

If you look at the code above you will see that there is one additional event handler registered with the import object. This event handler will fire every time a new object has finished importing. We will now use this event handler to finish the move operation by changing all links pointing to the original image to the new image and afterwards deleting the original image.

Lets look into the details.

The event handler gets the Url of the exported object and the Url of the imported object in the SPObjectImportedEventArgs:

  • SourceUrl
  • TargetUrl

Based on this information the following code will now give us the SPListItem object of the original image from the SourceUrl property.

string url = eventArgs.SourceUrl;
SPSite site = new SPSite(import.Settings.SiteUrl);
SPWeb web = site.OpenWeb(url, false);
SPListItem li = web.GetListItem(url); 

As next step we retrieve the number of backward links pointing to the original image. A backward link means that another object points to this object. A forward link on the other hand would point from the current object to a different object. Using the BackwardLinks collection we are able to identify all objects that a point to the exported object.

To adjust all links we need to follow all backward links pointing to the original object to adjust the links to point to the new object we get the links using the following code:

int count = li.BackwardLinks.Count; 
for (int i = count - 1; i >= 0; i--) 

   SPLink link = li.BackwardLinks[i]; 
   ...

Now we need to get the objects that are pointing to our source item by following the ServerRelativeUrl in each backward link:

SPLink link = li.BackwardLinks[i];
 
using (SPWeb rweb = linkSite.OpenWeb(link.ServerRelativeUrl, false)) 

   object o = rweb.GetObject(link.ServerRelativeUrl);
   ...
}

Now we known the object. The next step is to adjust the forward link. But to adjust the link we first have to cast the retrieved object to it's actually SharePoint type.

There are exactly two different object types that can create a link to our image: SPListItem and SPFile as these are the only object types that implement the ForwardLink property. And these objects also implement a method to adjust the forward link by replacing the link to the exported object with the link of the imported object:

object o = rweb.GetObject(link.ServerRelativeUrl);
if (o is SPFile)
{
   SPFile f = o as SPFile;
   f.ReplaceLink(eventArgs.SourceUrl, eventArgs.TargetUrl);
}
if (o is SPListItem)
{
   SPListItem l = o as SPListItem;
   l.ReplaceLink(eventArgs.SourceUrl, eventArgs.TargetUrl);
}

After we have successfully adjusted all links we can then savely delete the source image.

Here is the complete code for our event handler:

static void OnImported(object sender, SPObjectImportedEventArgs eventArgs)
{
   SPImport import = sender as SPImport;

   string url = eventArgs.SourceUrl;
   SPSite site = new SPSite(import.Settings.SiteUrl);
   SPWeb web = site.OpenWeb(url, false);
   SPListItem li = web.GetListItem(url);

   int count = li.BackwardLinks.Count;
   for (int i = count - 1; i >= 0; i--)
   {
      SPLink link = li.BackwardLinks[i]; 
      using (SPWeb rweb = site.OpenWeb(link.ServerRelativeUrl, false)) 
      { 
         object o = rweb.GetObject(link.ServerRelativeUrl); 
         if (o is SPFile) 
         { 
            SPFile f = o as SPFile; 
            f.ReplaceLink(eventArgs.SourceUrl, eventArgs.TargetUrl); 
         } 
         if (o is SPListItem) 
         { 
            SPListItem l = o as SPListItem; 
            l.ReplaceLink(eventArgs.SourceUrl, eventArgs.TargetUrl); 
         }
      }
   }
   li.Delete();

   web.dispose();
   site.dispose();
}

You can try this sample by creating a publishing site, create a sub web and upload an image to the "Images" library. Then create a page based on a page layout that has a Image Field and reference the uploaded image in this field. Now use the code shown above to move the image to the "Images" library in a different web.


2) How to control which of the objects in the export package need to be imported

The Content Deployment and Migration API itself does not provide a possibility to select specific objects for import. It will always import all objects included in the export package. In order to control which objects to import we again need to intercept the import using the "Started" event handler and remove all objects from the package that should not be imported.

This can be done using code similar to the following:

static void OnStarted(object sender, SPDeploymentEventArgs args) 

   
// assign new parents to the root objects if required.
   ...
   
// get the information about the location of the manifest file after decompression (if required)

   string tempFileLocation = args.TempDirectoryPath;
   
   // now we need get all manifest files from the SystemData.xml file in the tempdirectory path
   StringCollection manifestFilenames = GetManifestFilenamesFromSystemDataXmlFile(args.TempDirectoryPath + @"\SystemData.xml"); 

   // now we can manipulate the content of each of the manifest files and (e.g.) remove objects from the manifest.
   foreach (string manifestFilename in manifestFilenames)
   {
       DoTheRequiredManipulationsToTheManifestFiles(manifestFilename);
   }

The SystemData.xml file and the Manifest.xml files can be manipulated using normal Xml operations available in .Net framework.

Important to know when planning to manipulate the Manifest.xml files that each individual exported objects is reflected as a SPObject node. The SPObject nodes are sequentially serialized inside the manifest file. That means that subwebs are listed behind their parent webs but not as child xml nodes.

Now I see the following question coming up: Is it allowed to manipulate the Manifest.xml files?

The answer is yes! The xml schema of all the xml files in a content migration pack is officially documented and can (e.g.) be used by 3rd party companies to migrate content to WSS or MOSS:
http://msdn2.microsoft.com/en-us/library/bb249989.aspx

Published Thursday, August 30, 2007 7:11 PM by Stefan_Gossner

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Friday, August 31, 2007 12:41 AM by Noticias externas

# SharePoint Content Deployment and the Migration API

Stefan is back! J Stefan is in Redmond this week, and we had a chance to catch up! In fact, I had dinner

Friday, August 31, 2007 5:32 AM by SharePoint, SharePoint and stuff

# Deep Dive in SharePoint Deployment und Migration API

Stefan Goßner taucht in einer vierteiligen Serie in die Tiefen der SharePoint Deployment und Migration

Friday, August 31, 2007 9:40 PM by Andrew Connell [MVP MOSS]

# Fantastic, incredibly detailed, content on content deployment by Stefan

Fantastic, incredibly detailed, content on content deployment by Stefan

Friday, August 31, 2007 10:00 PM by Mirrored Blogs

# Fantastic, incredibly detailed, content on content deployment by Stefan

[via Stefan Gossner ] This past week I was in Redmond teaching my WCM401 development class in an open

Monday, September 03, 2007 6:03 AM by Mirrored Blogs

# Content migration API "Deep Dive" by Stefan Goßner

Body: Great series of posts by Stefan on how to use the Content Migration API. Very timely for me as

Tuesday, September 11, 2007 11:02 AM by Joycode@Ab110.com

# SharePoint内容部署与迁移API

今天凌晨加班的时候偶然翻到 Stefan Gossner 的这几篇文章,强烈推荐给大家: Deep Dive into the SharePoint Content Deployment and Migration

Tuesday, September 18, 2007 9:52 AM by yair

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Grate post, thanks.

But, what if my manifast.xml files weighs over 200 MB?

Tuesday, September 18, 2007 9:57 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Yair,

it shouldn't matter. But if you are concerned about this use the FileMaxSize export property.

This also controls the size of the generated manifest.

So you will end up with multiple manifest files then.

Cheers,

Stefan

Monday, September 24, 2007 3:57 PM by Luis Sousa

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi,

Your post was the best on content deployment with MOSS that I found on the internet. Better that MSDN documentation. :)

I wonder if you don't want to extend this article, with a part 5, where you can explain which of these features are available and work in websites with variations.

Congratulations!

Tuesday, September 25, 2007 5:49 AM by Connecting Systems the Microsoft Way

# MOSS / SharePoint Content Deployment

Great set of articles by Stefan Goßner : Deep Dive Into the SharePoint Content Deployment...

Friday, September 28, 2007 2:38 AM by Connected Systems Chilled Out Blog

# MOSS / SharePoint Content Deployment

MOSS / SharePoint Content Deployment

Tuesday, October 02, 2007 8:42 AM by Dragan Panjkov

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi, Stefan!

Can you explain why I receive some error messages on trying to migrate content between two MOSS machines. First machine was installed on english SKU, with 3 variations: english, serbian-latin and serbian-cyrillic. On that installation I installed language pack for serbian-latin when it became available. Second machine (destination) is empty moss with english sku and serbian language pack.

Here are error details:

Could not find language Serbian (Latin, Serbia). at Microsoft.SharePoint.Deployment.ImportRequirementsManager.VerifyInstalledLanguage(String id, String name) at Microsoft.SharePoint.Deployment.ImportRequirementsManager.VerifyLanguage(SPRequirementObject reqObj) at Microsoft.SharePoint.Deployment.ImportRequirementsManager.Validate(SPRequirementObject reqObj) at Microsoft.SharePoint.Deployment.ImportRequirementsManager.DeserializeAndValidate() at Microsoft.SharePoint.Deployment.SPImport.VerifyRequirements() at Microsoft.SharePoint.Deployment.SPImport.Run()

Thanks!

Dragan

Thursday, October 04, 2007 4:20 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Dragan,

you need to install the same language pack on both machines.

Cheers,

Stefan

Thursday, October 25, 2007 10:18 AM by Nita Arvind

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Stefan,

Me team is in a fix. We have some documents in a folder structure in a Content Management Application called Plumtree. Some of these Word documents have hyperlinks to eachother.

The requirement is for us to move these files and the folder structure as it is to a document library in sharepoint- this we are able to accomplish.

The next phase of the requirement was to update the hyperlinks in the documents with the new sharepoint URL. We are able to accomplish this in most cases using the SPfile.ReplaceLink function. But there are instances where this fails.

Eg: OLD URL: www.google.com?id=123

NEW URL: www.yahoo.com

It does nothing.

Is there something we might be doing wrong.

It works fine in cases where :

OLD URL: www.google.com/games.html

NEW URL: www.yahoo.com

Thursday, October 25, 2007 11:16 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Nita,

please open a support case for this.

This needs to be analyzed in more details.

Cheers,

Stefan

Thursday, November 08, 2007 11:04 AM by Placelight Blog

# useful links for sharepoint 2007 customization

useful links for sharepoint 2007 customization

Friday, January 04, 2008 7:03 PM by AllTec

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi

I want to migrate my content(documents in folder structure) from plumtree to MOSS 2007. How I should go ahead with this migration?

Thanks

AllTec

Monday, January 07, 2008 10:28 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi AllTec,

you would need to create a Content Deployment and Migration Package from the Plumtree content.

So you would need to write or purchase a tool that reads the content from Plumtree and creates the package. Then import the package into SharePoint.

The schema the package content has to follow is defined here:

http://msdn2.microsoft.com/en-us/library/bb249989.aspx

Cheers,

Stefan

Tuesday, January 22, 2008 8:20 AM by Paul

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi stefan,

I like to know where the settings(e.g. authentification) for the target Sharepoint will be handled, if the target system is in a differnet domain than the source. I can´t see anything around the SPImport class that could help.

best regards

Paul

Tuesday, January 22, 2008 8:27 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Paul,

there seems to be a misunderstanding.

SPImport can only be used against the local machine - not remotely.

Cheers,

Stefan

Monday, February 25, 2008 2:54 PM by Mike's Blog

# Deep Dive Into the SharePoint Content Deployment and Migration API

Stefan Goßner posted a great series of posts about the Content Migration API (formerly known as PRIME

Wednesday, February 27, 2008 11:47 AM by Michael

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Is this an approach that could be used to export a particular content type and import it into a totally new content type?

Is there an event that could override which site column/field control the content is imported into?  Or will you end up importing the content - and then changing the content types?

Wednesday, February 27, 2008 11:50 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Michael,

you would need to modify the export package to achieve this before importing.

Cheers,

Stefan

Friday, April 11, 2008 7:37 PM by Stefan Goßner

# Deep Dive into the SharePoint Content Deployment and Migration API - Part 6

[ Part 1 - Part 2 - Part 3 - Part 4 - Part 5 - Part 6 ] Requirements for a successful content deployment

Thursday, August 28, 2008 1:41 AM by Roopa

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hey,

I am trying to export and import a list which is having folders and sub folders within.Can you please tell me how to import items to the respective subfolders. presently, all the items are moving to the root folder.

Monday, September 08, 2008 8:16 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hallo Roopa,

this is discussed in section "2) Change the Parent of the imported objects during Import" of part 3.

Cheers,

Stefan

Tuesday, October 21, 2008 7:56 AM by roopa

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hey Stefan,

I have been trying to import a list.Export is goin on proper but, while import the following error is logged in :

------------------------------------------------

[10/21/2008 1:42:54 PM]: Start Time: 10/21/2008 1:42:54 PM.

[10/21/2008 1:42:54 PM]: Progress: Initializing Import.

[10/21/2008 1:42:54 PM]: Progress: Starting content import.

[10/21/2008 1:42:54 PM]: Progress: De-Serializing Objects to Database.

[10/21/2008 1:42:54 PM]: Progress: Importing Folder /abc/xyz/Lists/list for calenders/Item.

[10/21/2008 1:42:55 PM]: Progress: Importing ListItem /abc/xyz/Lists/list for calenders?id=6.

[10/21/2008 1:42:55 PM]: Error: Invalid file name

The file name you specified could not be used.  It may be the name of an existing file or directory, or you may not have permission to access the file.

  at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish)

  at Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents)

  at Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents)

  at Microsoft.SharePoint.SPListItem.MigrationAddOrUpdate(Boolean bAddNew, Boolean bIsPublish, Guid newGuidOnAdd, Boolean bNoVersion, Boolean suppressAfterEvents)

  at Microsoft.SharePoint.Deployment.ListItemSerializer.SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)

[10/21/2008 1:42:55 PM]: Progress: Import Completed.

--------------------------------------------------

I have no clue why is this happening.Please do suggest what might be the reason.

Thanks in advance,

Roopa.

Tuesday, October 21, 2008 9:24 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Roopa,

the problem code be the last item listed in the log and with the same possibility the next item that would be imported.

To analyze this further it would be required to analyze a memory dump for this exception.

Please open a support case for this to get this analyzed in more detail.

Cheers,

Stefan

Thursday, October 30, 2008 5:31 AM by rajee

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

hi stefan,

       I have two custom menus which will be given to the user.When two users try to run at same time it is executing only one job at a time.so how to handle this issue so that all the users are able to acess these custom menus for the deployments.Is there any way to create a job programtically.

Regards,

Rajee

Thursday, October 30, 2008 6:00 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Rajee,

you need to ensure that the jobs are not running in parallel as the content deployment and migration API is not designed to run more than one job at a time.

Also: did you already check out the quick deploy function? Because what you are talking about sounds like the functionality provided by this function.

Cheers,

Stefan

Thursday, October 30, 2008 7:39 AM by rajee

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

hi stefan,

   I tried searching for this quick deploy function but dint get any proper information on this.How to create a Quick deployment job and run that job programtically.

Cheers,

Rajee

Thursday, October 30, 2008 7:54 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Rajee,

the quick deploy job gets automatically created when you create a content deployment path between two site collections where the source site collection has the publishing feature enabled.

A publishing site collection is required for this feature. You cannot use it with team sites (e.g.)

Cheers,

Stefan

Thursday, October 30, 2008 8:26 AM by rajee

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

hi stefan,

  In our case we have some hundereds of sites which will have pages library.on those libraries we activated the custom menus.In our case we have internet users where they can move the pages to the Archival Site. I tried creating the Content Deployment path by using Central administrator.Mapping is very problematic as there are so many sites.

So is there any way to create content deployment path programtically so that we can create the path and update those details.Once deployment is done so that we can delete that path.If parallel jobs are there we will create two paths and run the job at different times.

Cheers,

Rajee

Thursday, October 30, 2008 8:34 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Rajee,

it would be required to create a path that copies content into a different location of the current site.

That is not possible. Neither programmatic nor manual.

You need to do this manually using the content deployment and migration API.

I would suggest to implement the console action as an action that writes the information what to copy in a list and implement the real copy operation as custom SharePoint timer job and execute it in OWSTIMER as it is done with the other content deployment jobs. This job then has to read the list to get the info what to deploy.

Then you don't have to bother about synchronization problems between actions.

Cheers,

Stefan

Thursday, October 30, 2008 8:52 AM by rajee

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi stefan,

    Thank you so much.What ever content you have provided in this bolg is fantastic.Really very useful for the content migration.

Cheers,

Rajee

Thursday, November 20, 2008 4:19 AM by Rajee

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

hi stefan,

   I am trying to import the Custom List Items i am getting error "Invalid Filename you specified couldn't be used.It may be the name of the exsistingfile or directory,or you may not have permission to access the file."

what could be the reason for this.

Cheers,

Rajee

Thursday, November 20, 2008 4:26 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Rajee,

I haven't seen this issue.

I would suggest to open a support case to get this analyzed in more detail.

Cheers,

Stefan

Thursday, January 22, 2009 7:42 AM by Rajee

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

hey stefan,

     We tried importing a page from One site collection to another site collection on different port.Import is sucessful but when we tried opening the page every time i am getting the "File Not found" error.

when we check the ULS Logs we are getting the error as "Medium   Unknown SPRequest error occurred. More information: 0x80070002

"01/14/2009 07:27:45.00  w3wp.exe (0x0368)                        0x1048 Windows SharePoint Services    General                        8nca Verbose  Application error when access /site1/site2/site3/site4/Pages/samplepage.aspx, Error=The file /site1/_catalogs/masterpage/samplelayout.aspx does not exist.

we can see the imported page in the Pages library.

I have no clue why is this happening..Please suggest the what could be the reason for this.

Cheers,

Rajee    

Thursday, January 22, 2009 7:53 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Rajee,

does the page layout exist as well?

The error message indicates that the page layout is missing - not the page itself.

Cheers,

Stefan

Thursday, January 22, 2009 8:34 AM by Rajee

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

hi Stefan,

      Page layout is there in the destination site.But when we tried opening the page we are getting this kind of Trace logs.why this page layout is not getting attached to the page which is imported in to the pages library.

Cheers,

Rajee

Thursday, January 22, 2009 8:40 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Rajee,

it seems it is attached - otherwise it would not try to load it from this location. But it seems the file cannot be opened for some reason.

Please open a support case with Microsoft to analyze what is causing the issue on your site.

Cheers,

Stefan

Wednesday, January 28, 2009 4:58 AM by STA

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Stefan,

Your post is very useful for me. I'm trying to export/import SPList from site to site. And I found that SPExportMethodType.ExportChanges cannot be used for SPList level. I think other way around is exporting site or web level with SPExportMethodType.ExportChanges. And then remove unnecessary things from manifest.xml file with eventhandler. Is it possible to do so? And I found Manifest.xml file has a lot of ObjectTypes, can I remove only ObjectType="SPList"?  Please give me idea.

Thanks,

STA

Wednesday, January 28, 2009 5:08 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi STA,

you can modify the manifest.xml file to get what you are looking for.

For details about what has to exist in the manifest file (which will allow you to decide what can be removed) can be found here:

http://msdn2.microsoft.com/en-us/library/bb249989.aspx

Cheers,

Stefan

Wednesday, January 28, 2009 10:35 PM by STA

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Stefan,

Thanks for your advice, I have another question. I need to synchronize two lists from different sites. I wonder Content Migration API can handle deleted items or not. After I run SPImport, all the items I deleted in source site are still remaining in destination site. with SPExportMethodType.ExportChanges.

Thanks,

STA

Thursday, January 29, 2009 3:08 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi STA,

export changes works on SPWeb level. Then it will only export changed list items.

Cheers,

Stefan

Thursday, February 12, 2009 5:44 AM by Lawrence

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Is there a way to migrate a single list item so that it updates the corresponding item in the target list rather than adding a new item to the list?

we have a customer who has their own copy of a SP site we created, and we would like to migrate any changes we make in ours to theirs. We have done some trial migrations but discovered that any updated items in our list always results in a new item in their list.

Our main issue is maintaing the list item ID.  If we update item ID=12 for example in our list, we want the migration to replace ID=12 in their list, whereas at the moment it is creating ID=99 (say) and still retaining ID=12.

The reason for this is because of lookups on that list. If another list points to ID=12 then we don't want to retarget that so it points to ID=99 (unless we have to = and if so, how could we do that in bulk....?)

thanks for any guidance you can give.

Thursday, February 12, 2009 5:46 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Lawrence,

updates to items are only supported with RetainObjectIdentity.

That means that the GUID and URL need to be the same on the target.

So you cannot do this together with reparenting.

Cheers,

Stefan

Thursday, February 12, 2009 6:03 AM by Lawrence

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Thanks Stefan.

So as I understand it, if we used RetainObjectIdentity that would work internally where we want to migrate content between

mydomain/siteA to mydomain/siteB

but not externally for

mydomain/siteA to theirdomain/siteA

Thursday, February 12, 2009 6:45 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Lawrence,

that is not correct. It will work for different domains as well.

Cheers,

Stefan

Tuesday, April 07, 2009 3:13 PM by SHarepoInT

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

can you please give a continuos, complete, and tested code example for exporting a list item and then importing it into a different list from start to finish? i have tried desperately to piece this code together but no matter what i do i get errors. when i click 'debug' my computer bursts into flames. plz help

Wednesday, April 08, 2009 6:38 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi SHarepoInT,

working code is below.

Cheers,
Stefan

 

using System;

using System.Collections.Generic;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Deployment;

namespace WssOMtest

{

   class Program

   {

       static void Main(string[] args)

       {

           // export

           SPSite site = new SPSite("http://localhost:4000");

           SPWeb web = site.OpenWeb("/");

           SPList list = web.Lists["MyList"];

           SPListItem listItem = list.Items[0];

           SPExportObject exportObject = new SPExportObject();

           exportObject.Id = listItem.UniqueId;

           exportObject.Type = SPDeploymentObjectType.ListItem;

           SPExportSettings exportSettings = new SPExportSettings();

           exportSettings.ExportObjects.Add(exportObject);

           exportSettings.FileLocation = @"c:\export\CopyListItem";

           exportSettings.FileCompression = false;

           exportSettings.SiteUrl = "http://localhost:4000";

           SPExport export = new SPExport(exportSettings);

           export.Run();

           web.Dispose();

           // import

           SPImportSettings importSettings = new SPImportSettings();

           importSettings.SiteUrl = "http://localhost:4000";

           importSettings.FileLocation = @"c:\export\CopyListItem";

           importSettings.FileCompression = false;

           importSettings.RetainObjectIdentity = false;

           SPImport import = new SPImport(importSettings);

           EventHandler<SPDeploymentEventArgs> startedEventHandler = new EventHandler<SPDeploymentEventArgs>(OnStarted);

           import.Started += startedEventHandler;

           import.Run();

           // cleanup

           site.Dispose();

       }

       // event handler to assign a new parent to the orphaned image in the package

       static void OnStarted(object sender, SPDeploymentEventArgs args)

       {

           SPSite site = new SPSite("http://localhost:4000");

           SPWeb web = site.OpenWeb("/PressReleases");

           SPList list = web.Lists["TargetList"];

           SPImportObjectCollection rootObjects = args.RootObjects;

           foreach (SPImportObject io in rootObjects)

           {

               io.TargetParentUrl = list.RootFolder.ServerRelativeUrl;

           }

           web.Dispose();

           site.Dispose();

       }

   }

}

Friday, April 10, 2009 1:13 AM by Rajee

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

hi stefan,

 We are facing one critical problem while importing the page into another Webapplication

Below is the Error Log for that

The Web application at http://son15873:22232/dealer/uskw/en/parts/supplierdocumentation/srdview1 could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

Please suggest what might be reason for this?

Friday, April 10, 2009 5:49 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Rajee,

I assume you already verified that the URL is valid, right? I haven't seen this error in such a situation. Please open a support case with Microsoft. to get this analyzed.

Cheers,

Stefan

Wednesday, April 15, 2009 10:03 AM by SHarepoInT

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hey Stefan,

Do you know if there's a way to retain permissions on a list item through this process? I've tried using IncludeSecurity = SPIncludeSecurity.All on export and import but it doesnt look like that has anything to do with permissions. Is there another setting or combination of settings that does this?

Thanks

Wednesday, April 15, 2009 1:05 PM by SHarepoInT

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

To update my last post, It turns out that IncludeSecurity = SPIncludeSecurity.All IS the way to retain permssions. The problem I'm having is that it doesnt work if the source and target are in different application pools. Neither does copying role assignments one by one, or pretty much anything else item, list, web, site, or sharepoint related. So, if you happen to know a way to get permissions across application pools that would be great but this probably isnt import/export related anymore so I'll understand if it doesnt get much attention

Wednesday, April 15, 2009 4:03 PM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi SHarepoInT,

this should work if you set SPImportUserInfoDateTime to ImportAll.

Cheers,

Stefan

Friday, April 17, 2009 4:46 PM by SharePoint List Migration

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Stefan,

I want to start off by thanking you for all the time and effort spent sharing your expertise with the SharePoint community.

The Problem: Migrating ListItems between two sites (A -> B) while preserving ID and author/editor info.  The content type of List B is different from List A (B has additional columns defined).  

From your posts my understanding is that: 1) ListItem ID can be preserved setting RetainObjectIdentity = true (does this only preserve List GUID or also ListItem IDs?)

2) Author/editor info can be preserved using the UserInfoDateTime setting.

Is it possible to leverage the migration api if there are differences between original and destination list content types?  Are there alternatives?

Any insight would be greatly appreciated.

Friday, April 17, 2009 5:45 PM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi,

1) it will preserve the GUID of list and item. I don't think it will preserve the integer ID of the item. That can change when being imported on the target

2) no that is not possible.

Cheers,

Stefan

Sunday, April 19, 2009 3:15 PM by SharePoint List Migration

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Thanks for the prompt reply.  

To clarify point 2)

You are saying that there is no way to use the migration api if:

Source List (field A, field B) and

Destination List (field A, field B, field C)

I cannot import only field A and field B data to the destination list?

Monday, April 20, 2009 2:36 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

In case that the target list has the same columns plus some additional it will work. Means the additional columns are empty.

But you cannot remap the columns from one column to another one.

Wednesday, April 22, 2009 11:19 AM by Narendra

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Stefan,

I have a MOSS installation for intranet and we are planning to use WSS for internet web facing site. The WSS is sitting at some hosting provider. Could I be able to export my MOSS content to the external facing WSS site using the technics that you are showing here.

Thanking you

Narendra

Wednesday, April 22, 2009 11:32 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Narendra,

only if the site does not use any MOSS specific features.

Cheers,

Stefan

Wednesday, April 22, 2009 11:41 AM by Narendra

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Stefan,

Some where you said,

SPImport can only be used against the local machine - not remotely.

I thought content won't be copying accross domains!

Thanks for this.

Second question,

How can I do this :) Little bit of insights please.

Thanking you very much.

Wednesday, April 22, 2009 11:56 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Narendra,

the info is correct. SPImport can only be used against the local farm. But you can copy on one farm, transfer the package to the target farm and then run SPImport there.

Cheers,

Stefan

Monday, May 25, 2009 9:38 AM by s

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi Stefan,

Do you have any idea how to get backward links from other SPWebApplications? The BackwardLinks collection doesnt include them.

I'm thinking about trying to use a search but I thought I'd ask in case you know an easier way.

Monday, May 25, 2009 9:54 AM by Stefan_Gossner

# re: Deep Dive into the SharePoint Content Deployment and Migration API - Part 4

Hi,

SharePoint manages links only within the same site collection. Links to other site collections are treated as external links. You will not find them in the BackwardLinks collection.

For such links you would need to implement your own link management.

Cheers,

Stefan

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker