You would want to setup a Sitecore Scheduled task to do this. You have 2 options:
1. C# Scheduled Task
The code to move an item is pretty simple:
var currentDb = Sitecore.Data.Database.GetDatabase("master");
var folderItem = currentDb.GetItem("/sitecore/content/AutoArchive/NewsArchive");
var archiveItem = currentDb.GetItem("/sitecore/content/AutoArchive/News/News01");
archiveItem.MoveTo(folderItem);
You would want to use the search API to get you a list of news items that need archiving rather than getting the News item and looping through the child items, depending on how many child items it has.
To create that as a scheduled task, create a class for the task:
using System;
using Utils;
namespace WebsiteNamespace
{
public class ArchiveNewsItemsScheduledTask
{
private static readonly object Monitor = new object();
public void Run()
{
lock (Monitor)
{
// Code to move the items here
}
}
}
}
Then add your config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<scheduling>
<agent type="MyNamespace.ArchiveNewsScheduledTask, MyAssembly" method="Run" interval="00:20:00"></agent>
</scheduling>
</sitecore>
</configuration>
Set the interval
to daily or however often you want to run the task to pick up items it needs to archive.
UPDATE: Get items based on expiry date
This is based on your code from the deleted question:
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)
{
// Only move the item if the expiry date is in the past
var expiryDate = (DateField)item.Fields["Expiration Date"];
if (expiryDate.DateTime < System.DateTime.Now.ToUniversalTime()) {
item.MoveTo(destinationContainer);
}
}
}
There are more efficient ways of doing this, but it should give you a start. I suggest you look up a simple Sitecore query, or for more performance use the Sitecore Search API and pull the items from the index
2. Use Sitecore PowerShell Extensions
Using SPE you can setup a scheduled task without having to write or deploy any .net code. Again moving an item is pretty simple:
$destinationPath = "/sitecore/content/AutoArchive/News Archive";
#templateName = "News"
Get-ChildItem master:/sitecore/content/AutoArchive/News | Where-Object { $_.TemplateName -match $templateName } | ForEach-Object {
Move-Item -Path $_.ItemPath -Destination $destinationPath;
}
Write a new SPE module that does the archiving, then create a scheduled task to run that SPE script. The instructions are already available for those things so I wont add all that detail here as its not the main answer to the question
Either option would work.
Are You Sure?
Some things to think about tho - automatically moving items will change the Urls that may already have links created to them, so how will you handle redirects or broken links?