Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom Code for Moving Item from one directory to another
using Sitecore.Configuration;
using Sitecore.Data.Items;
using Sitecore.Data;
using Sitecore.Data.Fields;
namespace sitecore.local.CustomCode
{
public class ItemMoving
{
private readonly Database _sourceDatabase = Factory.GetDatabase("master");
public void Execute()
{
var itemContainer = _sourceDatabase.GetItem("/sitecore/content/AutoArchive/News");
var destinationContainer = _sourceDatabase.GetItem("/sitecore/content/AutoArchive/News Archive");
if (itemContainer != null)
{
var items = itemContainer.Children;
foreach (Item item in items)
{
var expiryDate = (DateField)item.Fields["Expiration Date"];
if (expiryDate.DateTime < System.DateTime.Now.ToUniversalTime()) {
item.MoveTo(destinationContainer);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment