Skip to content

Instantly share code, notes, and snippets.

@tmamedbekov
Created June 6, 2017 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmamedbekov/85bb7dfbcc8ccab623c09a0bf3fbf979 to your computer and use it in GitHub Desktop.
Save tmamedbekov/85bb7dfbcc8ccab623c09a0bf3fbf979 to your computer and use it in GitHub Desktop.
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