Sitecore Transfer items from one database to another

In this article I will describe how to transfer items from one Sitecore database to another. Usually you transfer content by publishing. But in rare cases this is not an option:

  • You are not moving content from master to web
  • You are not moving content to a publishing target.
  • You are moving content to another path in another database.
  • You would like to avoid raising any events that would clear cache.

Before you start transferring content, you need to know the following:

  • Transfer does not retain the path structure, because a transfer is like a copy, just between databases. If you would like to retain the path, you must do it yourself.
  • The templates of the transferred items must exist in the target database. If not, Sitecore will raise an TemplateNotFoundException.
  • Transferring is done by copying the OuterXML of an item into a string and pasting this string to another database. This could be a very CPU and memory heavy process if you choose to copy the root of a large website.

Enough talk. Here is the code:

using Sitecore.Configuration;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Data.Proxies;
using Sitecore.Diagnostics;
using Sitecore.Exceptions;

namespace MyNameSpace
  public class ArchiveRepository
    public void Put(Item source, Item destination, bool deep)
      using (new ProxyDisabler())
        ItemSerializerOptions defaultOptions = ItemSerializerOptions.GetDefaultOptions();
        defaultOptions.AllowDefaultValues = false;
        defaultOptions.AllowStandardValues = false;
        defaultOptions.ProcessChildren = deep;
        string outerXml = source.GetOuterXml(defaultOptions);
          destination.Paste(outerXml, false, PasteMode.Overwrite);
          Log.Audit(this, "Transfer from {0} to {1}. Deep: {2}", new[]{ AuditFormatter.FormatItem(source), AuditFormatter.FormatItem(destination), deep.ToString() });
        catch (TemplateNotFoundException)
          // Handle the template not found exception


Parameter source is the item to copy, parameter destination is the item in the destination database to copy to. Parameter deep determines if you transfer one item of the whole tree.

I created a few more methods to allow for transferring an item from one database to another whilst retaining the path structure. By adding the destination database as private property I hard-code the repository to a specific destination database.

The method Put(item) takes a source item, creates the item path if not found, then transfer the item:

    private readonly Database _database = Factory.GetDatabase("DestinationDatabase");

    public void Put(Item item)
      Put(item, true);

    private void Put(Item item, bool deep)
      Item destination = _database.GetItem(item.Parent.ID);
      Put(item, destination, deep);

    private void EnsurePath(Item item)
      foreach (Item ancestor in item.Axes.GetAncestors())
        if (_database.GetItem(ancestor.ID) == null)
          Put(ancestor, false);


About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in c#, General .NET, Sitecore 6, Sitecore 7, Sitecore 8 and tagged , , , . Bookmark the permalink.

4 Responses to Sitecore Transfer items from one database to another

  1. Leo says:

    Hi Brian
    Your solution is smart.
    I am doing the same thing, but using ItemManager.AddFromTemplate() to create the item copy in the destination database.
    Your solution seems to perform better, because there is no need to iterate through all fields to duplicate field content.
    I tried replacing my code with yours, but it looks like the XML copy cannot handle blob fields. Image field content is not correctly duplicated to the destination item.
    Do you have a suggestion?


  2. Josh says:


    defaultOptions.IncludeBlobFields = true;


  3. Pingback: Which of my old Sitecore posts are still valid in Sitecore 9? | Brian Pedersen's Sitecore and .NET Blog

  4. Pingback: Copy items from one database to another – João Neto's blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.