Copy items from one database to another

In this short blog post, I want to share a code to copy items from one database to another. You usually use Sitecore publishing to transfer items. For example, from master to web database. Still, in some scenarios you might need to move items from web to master database like when you have a form that uploads files.

Before we start, this blog post is meant to add to what Brian Pedersen’s had already shared in his article Sitecore Transfer items from one database to another. His code works gracefully, but I noticed that when copying media items, the blob field named Media was not coming along.

Figure 1: Media field empty when transferring

This code is copied from a Sitecore functionality that transfers items between databases. It is located in Sitecore.Shell.Applications.Dialogs.TransferToDatabase, Sitecore.Client namespace. Unfortunately, it is not reusable, so we have to duplicate it somewhere else.

Although this functionality is named “transfer” or “move an item to another database”, that doesn’t mean the source item will be deleted after the transfer is completed. It basically, publishes that individual item to a target database and keeps the source item.

Figure 2: Transferring items to another database

Below is the complete code:

Here’s how you are supposed to call this method:

Figure 3: Using ItemTransferHelper class


Photo by Brina Blum on Unsplash

One thought on “Copy items from one database to another

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