Skip to content

September 26, 2007

InfoPath Form Services and Workflow Tasks

InfoPath Forms Services and Workflows in SharePoint can deal a one-two punch to your business problems.  It’s a simple form to create and a framework to take action on those forms.  However, there are a few caveats, however, one of them is that getting a form to open up in InfoPath Forms Services can be setup in the library where the form is stored but when a workflow task is created the link back to the item will try to open up in the InfoPath client (if present) – not in forms services.

Getting the document library to force the InfoPath form to open in InfoPath Forms Services can be done from the document library home page by selecting  Settings-Document Library Settings-Advanced Settings and changing the Browser-enabled Documents to Open browser-enabled documents to “Display as a web page”.

If you want to change the link so that it will open in the browser you’ll have to add a handler to the CreateTask activity.  I’ve added some support routines to break the code up into meaningful chunks. (that you can copy into your project).  The result looks something like:

private void createTask_MethodInvoking(object sender, EventArgs e)
string formsServerUrl = GetFormsServerUrl(workflowProperties.Item);
WorkflowTaskProperties.ExtendedProperties[SPBuiltInFieldId.WorkflowLink] = CreateUrlFieldString(“Open form for – ” + workflowProperties.Item.File.Name, formsServerUrl);

public static string CreateUrlFieldString(string name, string url)
return (string.Format(“{0}, {1}”, url, name));

public static string GetFormsServerUrl(SPListItem item)
return (item.Web.Url + “/_layouts/FormServer.aspx?XmlLocation=” + HttpUtility.UrlEncode(item.Web.ServerRelativeUrl) + “/” + HttpUtility.UrlEncode(item.Url) + “&OpenIn=Browser”);

Working from the bottom up, the GetformsServerUrl takes in the item you want the forms server URL for.  It does this by referencing the formserver.aspx and providing the correct parameters.  Above that CreateURLFieldString takes in the URL and a text description to create the string that you have to put into the field.

The actual MethodInvoking event for the createTask activity calls GetFormsServerUrl to get the actual URL and then CreateUrlFieldString to create a meaningful description for the link.  It then uses the SPBuiltInFieldId to get the Guid for the WorkflowLink field.

The net is a link that displays with a customized message and opens in the browser.

Recent Posts

Public Speaking