.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Starting a Approval workflow programatically

Posted By:      Posted Date: October 15, 2010    Points: 0   Category :SharePoint

Hi all,

I want to start a particular workflow programatically based on the item that is edited in a list. For this I have created all the required workflows on the list using Sharepoint . I have written Eventhandler for ItemUpdating event, and in that I try to start my workflow. The following is the code i use inside the event handler.

public override void ItemUpdating(SPItemEventProperties properties)


SPList oHorizon = properties.OpenWeb().Lists["Horizon Scanning"];

SPWorkflowManager manager = properties.OpenWeb().Site.WorkflowManager;

SPWorkflowAssociation asso = oHorizon.WorkflowAssociations[0];

SPWorkflow workflow = manager.StartWorkflow(properties.ListItem, asso, asso.AssociationData);

View Complete Post

More Related Resource Links

SharePoint 2010 Long Starting if start workflow programatically


In SharePoint 2010, I'm starting workflow #2 programatically from my workflow #1. See code below:

					SPList currentList = web.Lists[new Guid(ListId)];
					SPListItem currentListItem = currentList.GetItemById(ListItem);

					//resolve any lookup parameters
					string workflowId = base.ProcessStringField(WorkflowIdentifier);

					//find workflow association by name
					SPWorkflowAssociation workflowAssoc = currentList.WorkflowAssociations.GetAssociationByName(workflowId, Thread.CurrentThread.CurrentCulture);

					if (workflowAssoc != null)
						//start the workflow
						SPWorkflow workflow = site.WorkflowManager.StartWorkflow(currentListItem, workflowAssoc, workflowAssoc.AssociationData, SPWorkflowRunOptions.Synchronous);

And workflow #2  will hang with Starting status (1-10 minutes), Then the workflow #2 status would be modified  to Completed.

I couldn't find how to start the workflow # 2 immediately and complete immediately without several minutes delay

Terminating a SharePoint Workflow Programatically



I have a custome workflow coded in VS 2005 and deployed in to GAC and associated to a List in the SharePoint Portel through MS SharePoint Designer.


When an Exception happened in the code, the worklow instance' Status is shown as "Error Occured" and get suspended. since this workflow instance is "hung up" at this list item another instance of the workflow can't run. To run another instance you have to go into the SP Portal --> List and click on the "Error Occured" under the workflow of the item and then you have to terminate the workflow by clicking on the "Terminate this workflow now" link.


I just need to do this function ("Terminating the workflow") in the code in my Catch block where i handle the exception of the workflow activity.


could some one please tell me how to do this? or even point me in the right direction?


i've so far tried varity of:





ActivityBind activityBind = new

Serial approval workflow keeps running


I have a serial approval workflow created out of the box. The setting cancell this workflow when the document is rejected is selected. But if one of the approvers rejects it the workflow keeps running. After this is it will give acces denied errors for the other approvers.

So for example what is happening. The workflow is started and sends a email to persone 1. This persone approves so the workflow sends a email to persone 2. Persone 2 decided to reject the document. Now i want the workflow to be cancelled, but it keep running and sends a email to persone 3 for approval. If persone 3 opens the workflow he get's a acces denied error, i guess because of the reject.

Anyone has a idea what is happening here?

Workflow Approval Process

I have created a workflow for approval of a list.  I have listed two persons who can approve/reject and item.  My intent was to have either person be the appover.  Sharepoint apparently see's it differently; they need both persons to approve before the item can be finalized as either rejected or approved.  Is there a way to make it so that one of two people listed can approve a partiuclar workflow process??????   Thanks in advance, and yes, I am very, very new at this!

Any good Approval-type workflow tutorials for VS 2010?

Greetings.  I'm looking for some good tutorials (or books) on creating SharePoint 2010 Approval workflows in Visual Studio 2010.  I've spent a few hours digging through the search results on bing/google, but almost all of the examples (including content from Microsoft) show a very simple workflow in Visual Studio 2010 that doesn't contain approval steps.  I am looking for a more comprehensive tutorial on how to build a workflow that contains approval steps and evaluates the column values (i.e. evaluate a list column  if(Total Cost > 10000)) to determine branching.  InfoPath integration is a bonus but not required.  Anyone have any good links with solid tutorials?  Thanks in advance.

SPD workflow status show "starting" when I create a document from the library !!. and hangs

I have a document library in MOSS 2007. Have created a WF and that starts "autmatically when new item created" In the document library I have created couple of column those are mandatory (required columns) and user has to fill those column while uploading a document as well creating a document from library. WF has ran and completed succefully  when I use "upload" option to load a document.  As you are aware, when we "upload" a document, we will have to fill all "required columns" and the click "check in" command button.  After I do all this, document get loaded and WD ran succesfully. However, the WF is not running when I create a document (.docx) from this library (using "new" button) !!.  I have filled all required field in the document information panel . After save & exit from WORD application, I can see WF status as "starting". But, it never started and completed.  So I did following and found WF worked !! a) After creating document (.docx) using "new" option I found WF status "starting"!. So,  I did "Check-out and Check-in" manually from document library. After doing this,  WF ran and status has been changed as "completed" b) In SPD, I change workflow start option from "Automatic" to "Manually start".&nb

Workflow stuck on starting When using Win 7 / Office 2007

I've recently created custom workflows for a document approval process. At first I set the workflows to be started manually, for testing purposes and everything worked well. However when I changed the workflows to start automatically I started get problems. The workflow progress would stick on "Starting". Im running Win 7 And Office 2007, so i decided to do some troubling shooting on a different machine (XP and 2003) This time the workflow work perfectly...!   It is really strange as to why the workflows work fine on XP and 2003 and not with Win 7 and 2007. Can anybody shed any light on this or had the same problem? Thanks Chris

workflow approval multi users

I whant to build a workflow, 2 or more users must recieve a mail that there is a new document to approve. but when 1 user approved it, the workflow must end. and the approval from the other users must end olso? is this possible, i think i'm missing something. can it also be done with desigener or visual studio? regards

Error customizing Approval Workflow in SharePoint Designer

When attempting to customize OOTB Approval Workflow, message "Workflow is read only?"  Request copy errors with "Server could not complete your request" Details button produces blank.  Any clue?  I am the site collection administrator for the site and the secondary farm administrator.

OOTB Approval Workflow - Approval status could not be updated

I've setup up a standard OOTB (out of the box) approval workflow on a Pages library, in order to manage the approval of all pages created and updated.  This operates as expected, and the users are mostly happy, execpt for one scenario: Once a page has been submitted for approval, if the approver wants to edit the page, it stops the workflow (after prompting) which then requires the workflow to be started again.  They would like it so the approver can edit and then approve, without restarting the whole workflow process. There is a setting in the approval workflow configuration of the 'Complete the Workflow' section in the 'Cancel this Workflow when the' area, and by unchecking the 'Document is changed' option, I believe this should enable approvers to edit the page and then approve the page, without stopping the workflow  However, the workflow appears to operate as expected, except the page does not automatically get approved.  By looking in the workflow history, I can see the following error: Post-completion activity performed. Approval status could not be updated. I've tried this on two separate MOSS 2007 Enterprise farms, both are publishing sites and I'm running as a site collection administrator, both with the same results. Is anyone else getting this, is this normal?! Is there another way to approach this, without having to go

Approval workflow is not passing task instructions to workflow task page (WrkTaskIP.aspx)

Hi, Very weird issue. Never happened before. I have Document Approval workflow, based on built-in approval workflow, which is available in document libraries of every site in the site collection. You might know that when you kick off approval (even collect feedback) workflow, you can enter task instructions, which will be passed on to the workflow task page (WrkTaskIP.aspx), and also included in the email, which will be sent to approvers (reviewers in case it is a collect feedback workflow). I know that the users used to enter task instructions, and before, it was appearing in the workflow task page where you approve/reject it. Recently, they noticed that the task instructions textbox was being empty, though the instructions were being entered when the workflow was started. Moreover, it stopped showing task instructions for other tasks that existed for a long time. BTW, this is not the same in every environment we have, but I could not find any difference in the settings when I compared them. Has anybody faced this problem? Please help if you know the solution. Thank you!!! Regards, R.D.M.

Approval Workflow Failed to Start

they are the standard worflows in sharepoint we have suddenly starting getting the message Workflow Failed to Start retrying. the workflows it says not started we are the manually able to start them i tried deleting and recreating the workflows but still come up with this message there are 8 sites and they all have the same problems i had a look in the log and have this error 8e2r    Medium      Possible mismatch between the reported error with code = 0x81070504 and message: "There is no Web named "/Claims/default.aspx"." and the returned error with code 0x80070002.      01/29/2010 09:46:06.62     w3wp.exe (0x16C8)                           0x0288    Windows SharePoint Services       General                           8e2s    Medium      Unknown SPRequest error occurred. More information: 0x80070001   

Incoming E-Mail with attachment not starting SharePoint workflow (VS 2008)

I am working on SharePoint 2007 workflow in visual studio 2008. The workflow is attached to an email-enabled list and is supposed to automatically start on incoming email. It works fine when email (without attachment) is sent to the list but the workflow cannot start when the email is sent with attachment. There is no error message but the workflow status field is blank. The attachment field is also blank. When I manually run the workflow, it works fine. This problem happened on Staging and production servers. On Development server, the workflow works fine either way. The list is setup to save attachments. Any help please

Incoming E-Mail with attachment not starting SharePoint workflow (VS 2008)

I am working on SharePoint 2007 workflow in visual studio 2008. The workflow is attached to an email-enabled list and is supposed to automatically start on incoming email. It works fine when email (without attachment) is sent to the list but the workflow cannot start when the email is sent with attachment. There is no error message but the workflow status field is blank. The attachment field is also blank. When I manually run the workflow, it works fine. This problem happened on Staging and production servers. On Development server, the workflow works fine either way. The list is setup to save attachments. Any help please

Sharepoint Approval Complex Workflow Requirement

I have a very complex requirement of workflow to be developed. Here is it... There is a Sales Order form which user fills in. This form should have a header section which is static. Body section consist of questions which should be configurable. There are 2 answers to such questions. 1. Standarad & Other Exception. If user selects exception then more number of fields should be displayed which again should be configurable. For every exception answer to the question, there should be a provision to configure approver with a certain Role... e.g. GM, Controller etc.. This role would then have actual approvers who can change any time and as a result need to be again defined in config database. Again they would be based on the Business unit that form is filled in. Finally more questions can be added by admin which creates a new version of the form and from the day its released, all new records should show new versions however old should continue old. What would be the best sharepoint solution approach for this requirement?

Stuck in Page Approval Workflow "Do-Loop"

My colleagues and I are building an intranet site. I have created a page, and am attempting to submit it, so my colleague can add content. So far I have gone through this process 18 times (to no avail): 1) Checked Page In 2) Submitted Page on the Publish Tab 3) Opened Status window on Publish Tab. Selected the open Approval Workflow. Selected Edit. Selected Approve. Hit OK. I receive confirmation emails -- yes, the page has been submitted. yes, the page has been approved. Checking back at the Status page, the workflow shows that it is complete/approved HOWEVER -- my colleague cannot access the page. It shows on her screen that the page is checked out and I am editing it. When I click on the page link, it opens immediately in the EDIT PAGE view (with Editing Tools already launched)...it will not allow me to get out of this mode. Also, if this is germane, the auto-generated URL ends in "ControlMode=Edit&DisplayMode=Design"...

Controlling Content Approval in custom SPD workflow

I've designed a custom workflow using SharePoint Designer 2007 on MOSS 2007 to perform the following: User uploads a document to a document library. Workflow triggers and waits for designated Approvers to either Approve or Reject the document. IF REJECTED, the user that uploaded the document is sent an e-mail and the document is deleted from the document library. IF APPROVED, the document is moved to a second, "secured" document library. This all works fine except for one thing. I want to record in a custom column who actually approved the document. As the workflow starts as soon as the document is uploaded to the document library then the workflow is running under the context of that user - not the user who approves or rejects the document. Does anyone have any idea how I could capture who approves this document through my custom SPD workflow?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend