Three steps required to create the custome command in sitecore
- Create button in sitecore through content editor
- Create class with action for button click event
- Change in config file
Create button in sitecore through content editor
We create a button in our ribben for delete the 6 month backup folder from content tree
Steps for create the button in content tree
- Create a chunk
- Create a strip
- Create a ribbon
Create a chunk
- Login in sitecore, Go to desktop panel and select the core database (Why we are using desktop panel and core database, Reason is If we are changing anything related to the sitecore panel then we need to change in core database and change database option available in desktop panel only )
- click on chunk (/sitecore/content/Applications/Content Editor/Ribbons/Chunks)
- select the chunk node and right click and insert->Insert from template
- Choose /System/Ribbon/Chunk template, enter the Item Name "My Utility" or any
- select the "My Utility" node and right click and insert->Insert from template
- Choose /System/Ribbon/Large Button template, enter the Item name "Delete Old News"
If you want more command then follow the same steps
Create a strip
For this chunk, we need a strip where we display this command button like serialize, indexing tool
- click on strip (/sitecore/content/Applications/Content Editor/Ribbons/Strips)
- select the strip node and right click and insert->Insert from template
- Choose /System/Ribbon/Strip template, enter the Item Name "Custom Command" or any
- select the "Custom Command" node and right click and insert->Insert from template
- Choose /System/Reference template, enter the Item name "Custom Command"
- set reference value as per the figure
If you want more strips then follow the same steps
Create a ribbon
for this strip, we need a ribbon where we add this strip like Home, Publishing, Configure
- click on Ribbon and select Default node (/sitecore/content/Applications/Content Editor/Ribbons/Ribbons/Default)
- select the Default node and right click and insert->Insert from template
- Choose /System/Reference template, enter the Item name "Utility"
- set reference value as per the figure
Create class with action for button click event
- Create Class Library project in visual studio.
- Add sitecore Nuget Package from sitecore.org (Package: sitecore.kernel, sitecore.MVC)
- Add new item as a class
using Sitecore.Shell.Framework.Commands;
using Sitecore.Web.UI.Sheer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SitecoreUtilityHelper
{
public class DeleteNewsCommand : Command
{
public override void Execute(CommandContext context)
{
Sitecore.Context.ClientPage.Start(this, "DeleteNews");
}
protected void DeleteNews(ClientPipelineArgs args)
{
if (!args.IsPostBack)
{
var url = string.Format("/Command/DeleteNews");
SheerResponse.ShowModalDialog(url.ToString(), "900px", "600px", "", true);
args.WaitForPostBack(false);
}
}
}
}
- compile the code and copy the dll file in sitecore site bin folder (where you create the ribbon,strips and chunk)
Change in config file
- Go to "App_Config\Sitecore\CMS.Core" folder
- open "Sitecore.Commands.config" file
- add line according to the figure
Click Event you can find in chunk section
All steps is done.