Zoki's Blog

When future comes first! iDevolution

Start SharePoint Workflow Programmatically on List Items

Few days ago while working on a WSS 3.0 project I came a cross an issue that needed better solution that the one that we had in the moment. What we had was a custom list with a couple of items in it, and 2 workflows attached to the list. Both workflows were set to start automatically when new item is added or be started manualy by the administrator. While working on the test environment it was very easy to propagate new version of the workflows (remove the old version and add the new one) and start them manualy on the existing items. Taking in consideration that I had to do that for ~10 items in the list, it was not hard for me...but, what will happen in the future when this goes to production and the list have 1000 or more items??? I can't go through all items and manualy start the workflows...no way.
Well, the solution is a simple application that will allow you to explore your site collection, select the list, select attached workflow on that list and with one click of a button it will go through all items in the list and start the workflow.

The link to download the application is here. I hope it will help you in your daily work.
Cheers

UPDATE
You can find the full code for the application here.

Comments

arun said:

thank you so much for this tool! i just started out in the sharepoint world and was looking for a script of some sort to run exatly what your tool did.

great job and thank you!

# March 20, 2009 12:09 PM

Raul Queiroga said:

Kudos to you!! :-D

# April 6, 2009 11:19 AM

TheWire said:

awesome. saves a lot of time. thanks a lot!

# May 13, 2009 9:49 AM

Kent D. said:

Thanks! Saved me a lot of time!

# May 20, 2009 8:07 AM

Kent D. said:

Any idea why it doesn't list all of the lists the second time I try and run it?

I entered in the same site information and it lists all of the sites, but none of the lists within the sites.

# May 20, 2009 1:54 PM

Zoki said:

Can you provide more info about the issue? It should list all lists that are present in the site.

Do you get any exeption?

# May 21, 2009 5:23 AM

Kent D. said:

It lists the sites. Beneath the site I need it lists "Lists" and "Document Libraries". Beneath Lists, it only lists "Listings" and "Workflow Reports", and beneath that only "Items". The logs list "5/21/2009 9:17:40 AM INFO: Found totaly 0 workflows attached to list Listings".

One interesting thing: It does list the lists in a random set of sites before and after the one I need. Is there a timeout issue and it's not getting all of the data?

There are no errors in the Event Viewer, no exceptions.

# May 21, 2009 7:35 AM

Kent D. said:

Sorry to keep bugging, but this really is a helpful tool. Here is the error I believe you were looking for:

Potentially excessive number of SPRequest objects (284) currently unreleased on thread 1.  Ensure that this object or its parent (such as an SPWeb or SPSite) is being properly disposed. This object is holding on to a separate native heap. Allocation Id for this object: {7ACF40AE-DA37-4606-915D-5C78B3F9B3AD} Stack trace of current allocation:    at Microsoft.SharePoint.SPRequestManager.Add(SPRequest request, Boolean shareable)     at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)     at Microsoft.SharePoint.SPWeb.InitializeSPRequest()     at Microsoft.SharePoint.SPWeb.EnsureSPRequest()     at Microsoft.SharePoint.SPWeb.get_Request()     at Microsoft.SharePoint.SPListCollection.EnsureListsData(Guid webId, String strListName)     at Microsoft.SharePoint.SPListCollection.EnsureListsData(String strListName)     at Microsoft.SharePoint.SPListCollection.Undirty()     at Microsoft.SharePoint.SPBaseCollection.System.Collections.IEnumerable.GetEnumerator()     at Seavus.SharePoint.Tools.Workflow.FormMain.FillSiteCollectionTree()     at Seavus.SharePoint.Tools.Workflow.FormMain.btnView_Click(Object sender, EventArgs e)     at System.Windows.Forms.Control.OnClick(EventArgs e)     at System.Windows.Forms.Button.OnClick(EventArgs e)     at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)     at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)     at System.Windows.Forms.Control.WndProc(Message& m)     at System.Windows.Forms.ButtonBase.WndProc(Message& m)     at System.Windows.Forms.Button.WndProc(Message& m)     at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)     at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)     at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)     at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)     at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)     at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)     at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)     at System.Windows.Forms.Application.Run(Form mainForm)     at Seavus.SharePoint.Tools.Workflow.Program.Main()

# May 22, 2009 8:52 AM

Zoki said:

I see... The problem that you have is with the code written in your workflow. In fact what you are doing is that you have to many opened SPWeb or SPSite objects, which after their use need to be disposed properly. Every SPSite instance holds a reference to the unmanaged WSS world in the means of a field member of type SPRequest.

In order to avoid the problem in your code ensure to properly dispose the SPSite/SPWeb object.

From your stack trace we can see that there are 284 not disposed SPRequest objects which is really big number taking in consideration that the default number of maximum allowed objects is around 10 I think (not really sure).

To avoid this take a look at these two links which will help you solve the problem:

hristopavlov.wordpress.com/.../understanding-sharepoint-sprequest

msdn.microsoft.com/.../aa973248.aspx

Note that few months ago I had the same problem when on a list with 150-200 items i was starting the workflow with this tool and part of the workflows started with success and some of them throwed errors.

# May 23, 2009 4:24 AM

Kent D. said:

I guess I'm confused. This error comes from running your SharePoint.Workflow.Tools.exe program. Isn't the problem within that code?

# May 26, 2009 6:47 AM

Kent D. said:

BTW, I never get to the point to run the workflow since it doesn't list them (thus my problem).

# May 26, 2009 10:46 AM

Makayla said:

This is great, thanks for sharing.

The application runs perfectly from my server, but throws an exception noting it could not load file or assembly when I run it from my workstation. Any ideas?

Thanks again.

# May 27, 2009 10:23 AM

Zoki said:

@Kent D.: The stack trace you showed me is from your SP site LOGS right? The reason/s why you can't list the workflows can be because the workflow/s is not attached to list with name Listings (check in the list -> Settings -> Workflow Settings if workflow is attached to the specific list) or you are not browsing the correct site from the site collection...please double check and if it still not works email me on zoki.zlatanov@gmail.com.

@Makayla: What OS do you have on your workstation? Is it XP? The application will work only on a machine with WSS 3.0 installed cause it uses SharePoint dll's.

-

# May 28, 2009 1:42 PM

DavidK said:

Zoki, is the source code available for this tool?

Thanks,

# June 4, 2009 2:37 PM

Thomasb said:

I am trying to use this to wtart WF's on an infopath library, and it tells me the number of items in the list is 0 (even though there are a little over 900)

help?

# June 5, 2009 4:49 AM

Zoki said:

@Thomasb: Not sure whats happening...Can you give me more info please

@DavidK: just use Reflector and you have the code or if you like I can upload the code for download.

# June 6, 2009 10:25 AM

DavidK said:

Thanks Zoki, a source code download link would be great.

# June 8, 2009 9:50 AM

Zoki said:

The code is uploaded... You can find the link at the end of this post

# June 10, 2009 11:20 AM

GarykPatton said:

Hello, can you please post some more information on this topic? I would like to read more.

# June 16, 2009 5:52 AM

soargaiva said:

Thanks for post. It's really imformative read.

I enjoy to browse mkdot.net!

# June 18, 2009 2:47 PM

Confused said:

This looks like exactly what I need! Unfortunately, I'm getting an error when I enter the collection site url. Any ideas?

# June 22, 2009 2:27 PM

Zoki said:

Can you post the the exception please.

# June 23, 2009 10:01 AM

MichaellaS said:

tks for the effort you put in here I appreciate it!

# July 21, 2009 2:40 PM

Mike said:

I get the following error when running your app-->

************** Exception Text **************

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

File name: 'Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

  at Seavus.SharePoint.Tools.Workflow.FormMain.btnView_Click(Object sender, EventArgs e)

  at System.Windows.Forms.Control.OnClick(EventArgs e)

  at System.Windows.Forms.Button.OnClick(EventArgs e)

  at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

  at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

  at System.Windows.Forms.Control.WndProc(Message& m)

  at System.Windows.Forms.ButtonBase.WndProc(Message& m)

  at System.Windows.Forms.Button.WndProc(Message& m)

  at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

  at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

  at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

WRN: Assembly binding logging is turned OFF.

To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.

Note: There is some performance penalty associated with assembly bind failure logging.

To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

************** Loaded Assemblies **************

mscorlib

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.832 (QFE.050727-8300)

   CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll

----------------------------------------

Seavus.SharePoint.Tools.Workflow

   Assembly Version: 1.0.0.0

   Win32 Version: 1.0.0.0

   CodeBase: file:///C:/mlacom/SharePoint.Tools.Workflow.exe

----------------------------------------

System.Windows.Forms

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.832 (QFE.050727-8300)

   CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

----------------------------------------

System

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.832 (QFE.050727-8300)

   CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll

----------------------------------------

System.Drawing

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.832 (QFE.050727-8300)

   CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

----------------------------------------

************** JIT Debugging **************

To enable just-in-time (JIT) debugging, the .config file for this

application or computer (machine.config) must have the

jitDebugging value set in the system.windows.forms section.

The application must also be compiled with debugging

enabled.

For example:

<configuration>

   <system.windows.forms jitDebugging="true" />

</configuration>

When JIT debugging is enabled, any unhandled exception

will be sent to the JIT debugger registered on the computer

rather than be handled by this dialog box.

# July 22, 2009 12:36 PM

TomD said:

Is it possible to copy the DLL's to an XP machine, register them then run the tool from XP?

Only issue with running from the server is we have a few non-IT users who adminster their sites but not the server and do not have access.

Thanks

# July 27, 2009 11:46 AM

TomD said:

Sorry. It actually gives me an Access Denied message when running from the server:

Error message - Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I am running as a Site Admin account.

Any idea's?

# July 27, 2009 11:53 AM

Ondrej said:

Hi Zoki,

I appreciate your shared tool. It is realy good solution. I have a question regarding starting it as a command, I mean schedule execution on some time and start it with parameters automaticaly. Is it possible or do you think you could add this possibility?

# August 26, 2009 5:39 AM

Laura said:

Hello Zoki,

This application looks great but I can not see where the code is located.  The links provided open the application.

Could you repost the code or direct me to it?

Thank you!

~Laura

# August 26, 2009 6:53 AM

Mohsin said:

Here is the exception I get when I enter the URL and click View. Am i missing something??

See the end of this message for details on invoking

just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

File name: 'Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

  at Seavus.SharePoint.Tools.Workflow.FormMain.btnView_Click(Object sender, EventArgs e)

  at System.Windows.Forms.Control.OnClick(EventArgs e)

  at System.Windows.Forms.Button.OnClick(EventArgs e)

  at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)

  at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

  at System.Windows.Forms.Control.WndProc(Message& m)

  at System.Windows.Forms.ButtonBase.WndProc(Message& m)

  at System.Windows.Forms.Button.WndProc(Message& m)

  at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)

  at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

  at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

WRN: Assembly binding logging is turned OFF.

To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.

Note: There is some performance penalty associated with assembly bind failure logging.

To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

************** Loaded Assemblies **************

mscorlib

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)

   CodeBase: file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll

----------------------------------------

Seavus.SharePoint.Tools.Workflow

   Assembly Version: 1.0.0.0

   Win32 Version: 1.0.0.0

   CodeBase: file:///C:/Documents%20and%20Settings/cl07123/Desktop/SharePoint.Tools.Workflow/SharePoint.Tools.Workflow.exe

----------------------------------------

System.Windows.Forms

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)

   CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

----------------------------------------

System

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)

   CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll

----------------------------------------

System.Drawing

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)

   CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

----------------------------------------

System.Xml

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)

   CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll

----------------------------------------

************** JIT Debugging **************

To enable just-in-time (JIT) debugging, the .config file for this

application or computer (machine.config) must have the

jitDebugging value set in the system.windows.forms section.

The application must also be compiled with debugging

enabled.

For example:

<configuration>

   <system.windows.forms jitDebugging="true" />

</configuration>

When JIT debugging is enabled, any unhandled exception

will be sent to the JIT debugger registered on the computer

rather than be handled by this dialog box.

# September 1, 2009 2:06 PM

mcdonalds coupons said:

Thank you much for that great entry.

# September 13, 2009 1:35 PM

Zoki said:

@Mike and @Mohsin:

You need to run the tool on PC where WSS/MOSS is installed.

@TomD:

Possible only on 64bit XP

@Laura:

I've tried the link above and works. write me your email if you want me to sent you the code.

# October 19, 2009 1:44 PM

rf said:

Great work Zoki. Excellent tool.

The link provided above opens the application. Could you please repost the code link or point me to it?

Thanks.

PS

# January 13, 2010 11:52 PM

vuzzfyision said:

Nice program, I was trying to find a way to extract the start workflow for all items action to use as a link in a content editor web part

# February 15, 2010 9:29 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)