Created
June 6, 2017 14:55
-
-
Save tmamedbekov/85bb7dfbcc8ccab623c09a0bf3fbf979 to your computer and use it in GitHub Desktop.
Custom Code for Moving Item from one directory to another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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