Home Change language: Register | Log in
Beta cloud
Improve your life online
Click to learn more
Click to learn more
Click to learn more

This task is currently locked by a running workflow and cannot be edited

Sometimes SharePoint users receives an error

This task is currently locked by a running workflow and cannot be edited.

There are a lot of causes of this problem. How to unlock workflow locked task?
I wrote a program which unlocks that task:

using System; 
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
 
namespace UnlockWorkflowTask
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.Write("Enter site Url: ");
                string siteUrl = Console.ReadLine();
                Console.Write("Enter web Url: ");
                string webUrl = Console.ReadLine();
                Console.Write("Enter task list GUID: ");
                string listId = Console.ReadLine();
                Console.Write("Enter task item ID: ");
                string itemId = Console.ReadLine();
                using (SPSite site = new SPSite(siteUrl))
                {
                    using (SPWeb web = site.OpenWeb(webUrl))
                    {
                        SPList list = web.Lists[new Guid(listId)];
                        SPListItem item = list.GetItemById(int.Parse(itemId));
                        object version = item[SPBuiltInFieldId.WorkflowVersion];
                        if (version != null)
                        {
                            string v = version.ToString();
                            if (!v.Equals("1"))
                            {
                                Console.WriteLine("Task item is locked. Workflow version is {0}", v);
                                Console.Write("Unlock task item (yes/no)? ");
                                string answer = Console.ReadLine();
                                if (answer.Equals("yes"))
                                {
                                    item[SPBuiltInFieldId.WorkflowVersion] = 1;
                                    item.SystemUpdate();
                                }
                            }
                            else
                            {
                                Console.WriteLine("Task item is unlocked.");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Version is null");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.WriteLine("Done");
            Console.ReadLine();
        }
    }
}

Enjoy it.

Tags: Programming, SharePoint
Created on: 2013-11-14 11:15:26
Updated on: 2013-11-14 11:15:26