July 15, 2024

Dear Sitecore Family,

A very small but useful post today.

I am sure all of us at some point in time have come across programmatically generating Sitecore Items while automating some task. And if sometimes out of those, also include fetching the Sitecore Workflow and which state the item is in.

So here we go:

[code language=”csharp”]

Database master = Factory.GetDatabase("master");
Item contentItem = master.GetItem("SOME_ITEM_ID_OR_PATH");
WorkflowState currentState;
if (contextItem != null)
IWorkflow itemWorkflow = master.WorkflowProvider.GetWorkflow(contentItem.ID.ToString());
if (itemWorkflow != null)
currentState = itemWorkflow.GetState(contentItem);


Hope this helps.

Happy Sitecoring! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *