Quantcast
Channel: Jevgeni Borozna's blog
Viewing all articles
Browse latest Browse all 40

Workflow ASPX Initiation Form bug in Visual Studio 2010

0
0

When you are adding Workflow Initiation Form to your Visual Studio project, then Visual Studio generating aspx page with buttons and code behind with some lines of code.

SharePoint workflow can be associated with list, site or content type. This generated code works fine with workflows associated with List, but if your workflow is associated with list content type, then when you will click Start button – you will get exception.

This error is in method StartListWorkflow() at following line of code:

SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)];

Exception will be thrown on next line, because association will null, if workflow was associated with content type.

To solve this problem you can replace this line of code with following code:

SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)];
if (association == null)
{
   association = workflowListItem.ContentType.WorkflowAssociations[new Guid(associationGuid)];
}

Now entire method should look like following:

private void StartListWorkflow()
{
   SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)];
if (association == null)
   {
      association = workflowListItem.ContentType.WorkflowAssociations[new Guid(associationGuid)];
   }
   this.Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData());
   SPUtility.Redirect(this.workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current);
}

Viewing all articles
Browse latest Browse all 40

Latest Images

Trending Articles





Latest Images