I wanted to build something similar to the following article: Schedule Sitecore Database cleanup tasks programatically

I do know that the cleanup database functionality is in Sitecore's launchpad -> Control Panel in my instance running version 8.1

The author does, what I believe, is a custom setup to call Sitecore's cleanup service. Code from the article is the following:

    namespace Sitecore.Foundation.ScheduledTasks.Services
    using System;
    using System.Collections.Generic;
    using System.Web;
    using log4net;
    using Sitecore.Data;
    using Sitecore.Data.Items;
    using Sitecore.Diagnostics;
    using Sitecore.Mvc.Extensions;
    using Sitecore.Mvc.Presentation;
    using Sitecore.Pipelines;
    using Sitecore.Pipelines.RenderField;
    using Sitecore.Tasks;
    using Sitecore.Web.UI.WebControls;
    using Sitecore.ExperienceContentManagement.Administration.Helpers.DbCleanup;

    public class ScheduledTasksService
        public void Execute(Item[] items, CommandItem command, ScheduleItem schedule)

        public void CleanupBlobs()
                CleanupTaskRunner runner = new CleanupTaskRunner();
                TaskToRun task = new TaskToRun();
                task.Database = "web";
                task.Task = CleanupTasks.CleanupBlobs;
                runner.RunCleanUp(new TaskToRun[] { task });
            catch(Exception e)
                Log.Error("Error while cleaning Blobs table", e, this);

I wanted to know if there is a more standard way of doing so. I don't have access to the Sitecore.ExperienceContentManagement.Administration.Helpers.DbCleanup

  • Not sure what the question is. The code shown is triggered from /sitecore/system/tasks - there will be a Command referencing ScheduledTasksService, and there will be a Schedule item with the schedule. Here is an old post addressing how to handle code that you want to run recurringly: SItecore Scheduling. If the site can run the code that you posted then you can always decompile the dll in question if you want to see that implementation of the Cleanup code. Jun 2 at 2:02
  • 1
    There is a dll called Sitecore.ExperienceContentManagement.Administration.dll, the author of the post extracted the relevant code from the dll and pasted it in a scheduler. Are you saying your are getting red squiggly lines in Visual Studio when you copy paste his code? You might need to add Sitecore references to your project through NuGet to get the Intellisense to recognize that your custom code can invoke Sitecore's native code. Jun 2 at 2:15
  • Thank you so much for the comments. Yes indeed I was having that issue of red squiggly lines. What would be the package I need to get from NuGet?
    – coolzoa
    Jun 2 at 16:17
  • You can add the nuget package Sitecore.ExperienceContentManagement.Administration specifying your sitecore 8.1 version Jun 2 at 19:11
  • Many thanks, it worked as expected.
    – coolzoa
    Jun 2 at 21:10

If you want to automate the cleanup service without writing any custom code you can use sitecore powershell to create a task as described in the documentation https://doc.sitecorepowershell.com/modules/integration-points/tasks, that will call a maintenance script under the System Maintenance module (/sitecore/system/Modules/PowerShell/Script Library/SPE/Maintenance/System Maintenance/Tasks/Clean up databases):

enter image description here

In order to install SPE you can follow the steps described in the installation doc https://doc.sitecorepowershell.com/installation.

In order to fix the compilation error for the namespace Sitecore.ExperienceContentManagement.Administration.Helpers.DbCleanup you need to add the nuget package Sitecore.ExperienceContentManagement.Administration specifying your sitecore 8.1 version

  • Many thanks. I will suggest this to the team as well since we currently don't have SPE installed.
    – coolzoa
    Jun 2 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.