Sitecore Tip: Get Current Workflow State of a Sitecore Item

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:

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

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.