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.

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.

Below is the complete code:

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

Credits

Photo by Brina Blum on Unsplash

comments powered by Disqus