I am making a tool to migrate/update specific content (list items and documents) from a farm to another. A little bit like the SharePoint Content Deployment Wizard, but with custom specifications from my client.
Using the Content Deployment API seems a good idea.
The site collections in each farm were created using standard process (using a custom site definition provisionning list and elts). I don't think I should use "RetainObjectIdentity" because the Guids are different between the 2 farms.
When I export/import data :
- Documents are correctly added/updated, but it's not the case for list items :
- It doesn't update existing list items. It always add new one.
So here is my question : What is the best solution to update existing list items (they don't have same GUIDs between site collections) ? I would like to retain the ListItem.ID (not UniqueID). Is that possible ? Is there a solution to tell the API to restore This Item to this one ? On the worst case, I can delete existing items before importing, but the items would lose their original ListItem.ID (int)...
Or I can forget the Content Deployment API...
Below : the code I am using :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Deployment;
using Microsoft.SharePoint;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Export();
Import();
}
static void Import()
{
using (SPSite site = new SPSite("http://localhost:5555/sites/aa/"))
{
using (SPWeb web = site.OpenWeb())
{
SPImportSettings settings = new SPImportSettings();
settings.SiteUrl = site.Url;
settings.FileLocation = @"c:\export";
settings.BaseFileName = "blop.cmp";
settings.RetainObjectIdentity = false;
settings.CommandLineVerbose = true;
SPImport import = new SPImport(settings);
import.Run();
}
}
}
static void Export()
{
using (SPSite site = new SPSite("http://localhost:5555"))
{
using (SPWeb web = site.OpenWeb())
{
SPList listDocs = web.Lists["Shared Documents"];
SPListItem item = listDocs.Items[0];
SPExportObject obj = new SPExportObject();
obj.Id = item.UniqueId;
obj.Type = SPDeploymentObjectType.ListItem;
SPList listTasks = web.Lists["Tasks"];
SPListItem item2 = listTasks.Items[0];
SPExportObject obj2 = new SPExportObject();
obj2.Id = item2.UniqueId;
obj2.Type = SPDeploymentObjectType.ListItem;
SPExportSettings settings = new SPExportSettings();
settings.IncludeVersions = SPIncludeVersions.LastMajor;
settings.SiteUrl = site.Url;
settings.IncludeSecurity = SPIncludeSecurity.None;
settings.FileLocation = "C:\\export";
settings.BaseFileName = "blop";
settings.CommandLineVerbose = true;
settings.ExportObjects.Add(obj);
settings.ExportObjects.Add(obj2);
settings.OverwriteExistingDataFile = true;
SPExport export = new SPExport(settings);
export.Run();
}
}
}
}
}