Posts Tagged workflow

SharePoint: Associate Workflow with a list programmatically


We need to associate a workflow with a list or create an instance of workflow for a list using SharePoint Object Model (OM)


In order to associate workflow with a list, we will be using CreateListAssociation method of SPWorkflowAssociaition class. We need following four values:

  • baseTemplate – The workflow template on which to base this workflow association.
  • Name – The name to give this workflow association.
  • taskList – The task list on which to create workflow tasks for this workflow association.
  • historyList – The list to which to log workflow history events

Code is as under:

using(SPSite spSite = new SPSite(“SiteURL”))


SPWeb spWeb = spSite.OpenWeb();

SPList assocList = spWeb.Lists[“NameOfTheList”];

SPWorkflowTemplate wflTemplate = spWeb.WorkflowTemplates.GetTemplateByName(“NameOfWorkflowTemplate”, System.Globalization.CultureInfo.CurrentCulture);

SPList wflTaskList = spWeb.Lists[“Tasks”];

SPList wflHistoryList = spWeb.Lists[“Workflow History”];

SPWorkflowAssociation wflAss = SPWorkflowAssociation.CreateListAssociation(wflTemplate, “NameOfTheWorkflow”, wflTaskList, wflHistoryList);

wflAss.AutoStartChange = false;

wflAss.AutoStartCreate = false;

wflAss.AllowManual = true;

spWeb.AllowUnsafeUpdates = true;



spWeb.AllowUnsafeUpdates = false;


Comments (1)

SharePoint: Workflows Implementation

In this article we have tried to explore implementation details of workflows in SharePoint 2007 and 2010. SharePoint provides us with three flavors of workflows, namely, Out Of the Box (OOTB), SharePoint Designer (SPD) and Visual Studio workflows. We will discuss implementation details of OOTB and SPD workflow w.r.t. to SharePoint 2007 (MOSS) and SharePoint 2010.

Out Of the Box Workflows: OOTB workflows are workflows which come with SharePoint server installation.

In MOSS, these workflows come in rigid form. You can’t customize them. The only option available is to create instance of OOTB workflows in different list or libraries and run them as they are. The instance details of OOTB workflows are stored in content database.

In SharePoint 2010, OOTB workflows are also termed as “Globally Reusable Workflows”. Other than “Three State workflow” which comes with SharePoint Foundations (free of cost), all other workflows comes with server or enterprise licenses. Great news is that these workflows can be customized using SPD 2010. The definition of OOTB workflows can be found using SPD 2010. Open site in SPD 2010 and select “All Files”. In the right pane, select “_catalogs” and then “wfpub”, you will be able to find OOTB workflows.

When you customize “Globally Reusable Workflow”, the definition of newly created workflow is stored in a list “workflows”.

SharePoint Designer Workflows: Workflows created using SPD are termed as SPD workflows. They are also called declarative workflows because they consist of Extensible Markup Language (XOML) rather than compile code as in the case of Visual Studio workflows.

In SPD 2007, we have only one type of workflow, namely, List workflow. In case of SPD 2010, we have three different types of workflows, namely, List, Reusable and Site workflows. When we create a new SPD workflow, a list “workflows” is created if don’t exist. Workflows list is not visible in SharePoint UI and can be accessed via SPD or SharePoint Object Model (OM). We can traverse workflows list using OM as under:

using (SPSite spSite = new SPSite(“Site_URL”))


SPWeb spWeb = spSite.OpenWeb();

SPList spList = spWeb.Lists[“workflows”];

foreach (SPListItem spListItem in spList.Items)





In case of SPD, open site in SPD and select “All Files”. In the right pane, select “workflows” and you will be able to find SPD workflows

Workflows list contains all the files related to a particular workflow. For each SPD workflow, three or four files are created depending upon the existence rules or conditions.

  • xoml – Contains all the activities included in the workflow in Extensible Application Markup Language (XAML) format
  • xoml.wfconfig.xml – Contains details of the list or site GUIDs and start configuration of the workflow
  • xsn or aspx – In MOSS, an aspx page is created for starting workflow. In SharePoint 2010, we have InfoPath form in place of aspx page
  • xoml.rules – Contains workflow rules if used

In the next post we will discuss the issues relating to migration of SPD workflows.

Comments (1)

SharePoint Workflow: Failed on Start (retrying)


We created a visual studio workflow which contains initiation form. Workflow was associated with multiple content types. Workflow works well when deployed using visual studio. When workflow deployed using WSP, it was crashed showing “Failed on Start (retrying)” or “Error Occurred” status.


When we add “Workflow Initiation Form” using “Add” -> “New Item”, following method is responsible for running workflow:

void StartListWorkflow()


SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new

this.Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData());

SPUtility.Redirect(this.workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current);


In the above method, following method looks for workflow association with the list:

SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new

But we have associated workflow with the content types, not with the list. This results in null value in the SPWorkflowAssociation type variable “association”. When “StartWorkflow” is called, it resulted in exception.

We changed the above line of code with following line:

SPWorkflowAssociation association = this.workflowList.ContentTypes[this.workflowListItem[“Content Type”].ToString()].WorkflowAssociations[new

In the above code, instead of finding association from list, workflow looks association using content type as workflow is associated with content type not list. This did the trick.

Comments (4)

SharePoint: Associate visual studio workflow with multiple Content Types


We need to associate multiple content types with the custom workflow created in visual studio 2010.


In the elements.xml file look for <AssociationCategories>. Appended with ;#”
among Content Type IDs. Example:




Leave a Comment

SharePoint Designer Workflow: Date Field Empty / Null Check

We need to auto initiate a workflow as soon as document is uploaded based upon criteria that document has date in “Expiration Date” field. In order to check whether date field has value or not, we can use following solution as SharePoint Designer doesn’t provide any direct way to check:!1CC1EDB3DAA9B8AA!498.entry

But these solutions were not properly working in our case as soon as document is uploaded, workflow is triggered and we were late to full value.


We pause workflow for 5 minutes at first step and requested user to fill value within 5 minutes of uploading documentJ.

Leave a Comment

MOSS 2007: You cannot create alerts for lists for which users can only read their own items

We tried to set up alerts for users for a list with customized permissions. Following error appeared: 

You cannot create alerts for lists for which users can only read their own items. 


Set up a workflow using SharePoint Designer which served same purpose.

Leave a Comment