Office Workflow Designer Managed Extensibility Framework (MEF)

The latest check-in adds Managed Extensibility Framework (MEF) to enable expression builder plug-ins. In addition, the source code shows how to create a SharePointItems workflow activity designer.

The source code is located at

SharePointItems Activity Designer

The SharePointItems activity designer located in SharePointItemsDesigner.xaml and QueryDesigner represent SharePoint item operations. The current version also shows a simple CamlWhere activity. With this activity designer, a workflow can perform GetItems, Delete and Update operations against a SharePoint list applying a single CamWhere query. A future release will add the ability to connect CamWhere activity logical operators.

Managed Extensibility Framework (MEF) Expression Builders

Numerous code changes were made to integrate MEF into the workflow designer. The changes enable the opportunity to create expression builder plug-ins.

Highlight of interfaces and classes added

abstract class ExpressionBuilderBase : IExpressionBuilder

abstract class ExpressionBuilderItemsProviderBase : IExpressionItemsProvider

abstract class ExpressionTypeConverterBase : IExpressionTypeConverter    

Example MEF Import

[ImportMany(AllowRecomposition = true)]
public ObservableCollection<Lazy<IExpressionExtension, IExpressionBuilderMetadata>> extensions { get; set; }

Resolve MEF builders

pathBuilder = this.ResolveBuilder(this.ExpressionPath);

if (pathBuilder != null)


    pathBuilder.ItemsProvider = Extension<IExpressionItemsProvider>


    pathBuilder.Converter = Extension<IExpressionTypeConverter>


    pathBuilder.OnUpdated = Builder_OnUpdated;

    expressionMenu.Visibility = Visibility.Visible;


TExtensionType Generic Method

private TExtensionType Extension<TExtensionType>(string path, string extensionAttribute)


TExtensionType extension = default(TExtensionType);

List<Lazy<IExpressionExtension, IExpressionBuilderMetadata>>
    targetExtensions = null;

if (expressionMappings.ContainsKey(path))


if (expressionMappings[path].ExtensionElement.Attribute(extensionAttribute) != null)


string typeName = expressionMappings[path].ExtensionElement.Attribute(extensionAttribute).Value;

targetExtensions =

    .Where(t => t.Metadata.Name.Equals(typeName))
    .Select(t => t))

if (targetExtensions.Count > 0)


extension = (TExtensionType)targetExtensions[0].Value;

ExtensionContextName =




return extension;


Resolve Expression Builder

private IExpressionBuilder ResolveBuilder(string path)


IExpressionBuilder extension = Extension<IExpressionBuilder>(path, ExpressionMappings.ExtensionAttributes.builderType.ToString());

if (ExtensionContextName == “MenuItemsBuilder”)


extension.ItemsControl = this.expressionMenu;


return extension;



Office 2010 Workflows


One of the greatest challenges facing development teams, or individual departmental developers, is the integration of business logic or rules into an application. A series of posts will show how to integrate Windows Workflow 4.0 for business logic into Excel 2010, Word 2010, Outlook 2010 or Access 2010.


A team leader creates a SharePoint site that has many lists that are required to manage her team’s mission. She wants to change these lists in an ad-hoc manner—perhaps updating announcements and tasks from an Excel spreadsheet or Word document. She has minimal development skills and wants to write a small custom application to help her manage this. She could use an Office Workflow 4.0 designer and SharePoint 2010 Client Side code activities and Office Open Xml activities to create such a solution.


Microsoft Windows Workflow 4.0 (WF4) is an architectural approach for enabling shared business logic between many .NET applications. WF4 can be invoked on the client, such as an Office .NET add-in blended with SharePoint 2010 Client Object Model (CSOM) code activities or as part of a Windows Communication Foundation (WCF) application. In addition to a workflow platform, WF4 ships with a designer capable of being hosted in any .NET application such as an Excel or Word VSTO project. This article and accompanying source code shows how to get started hosting a custom workflow designer in an Excel or Word add-in. The designer includes a toolbox containing some core workflow activities, a custom expression editor, a few custom SharePoint 2010 activity parts and a few Office XML activities. Using the add-in, a user can design and run workflows that integrate with SharePoint 2010 from within Excel 2010 or Word 2010.

Source Code

The source code of the next few posts is located at

Security Note The current sample source code allows any desktop user to design and run an Office Workflow. A production application would only allow authorized users to design and run workflows.


The upcoming posts will discuss points of interest when integrating Windows Workflow 4.0 and related technologies into an Office Add-in. Integrating Windows Workflow 4.0 into Office that invoke SharePoint 2010 and Open Office Xml code activities requires numerous technologies. The posts will cover the following topics

  • Windows Workflow 4.0
  • SharePoint 2010 Client Object Model – A client API that allows you to interact with SharePoint sites from a .NET 3.5 or above managed application.
    • SharePoint 2010 CRUD Activities
    • SharePoint Permissions
  • Office Open Xml – A managed code API for strongly typed part and content classes to manipulate Open XML documents.
    • Composite Office DocumentParts Activity
    • Abstract ContentPart Activities
  • View Publishers – ViewPublishers are similar to an interface or abstract class in that they define the properties of a View change.
  • Using LINQ – Various code snippets showing the use of LINQ for SharePoint CSOM and other uses.
  • Word and Excel
    • Workflow Ribbon
    • Activity Task Pane
    • Tracking Participant Subscriber

Please refer to the document located at for the remainder of this post.

Sample Workflow Designer

The upcoming posts will dissect how to create a custom Workflow Designer that can run in any Office Add-in. The potential of an Office Workflow Designer and custom business activities is to enable more rapid Office application development. The activity designers require .NET development skills; however, the departmental business logic can be created with a Power User skillset.

Sample Activity Designers

The accompanying source code, and future source code, has several sample Activity Designers. A custom activity designer can have any WPF controls including a context sensitive SharePoint 2010 menu. The figure below illustrates a popup menu containing menu items of available SharePoint 2010 lists on localhost.

Office Open Xml DocumentParts

A DocumentParts activity designer allows a workflow user to drag Excel Office Xml content parts into a SharePoint document context. The user simply enters the SharePoint Url , Document Library and Document Name. Then the user drags Excel RangePartActivities into the DocumentParts designer to get cell data. All Office Xml details such as retrieving the Excel Xml stream and getting cell parts are hidden from the user.

Important The sample is intended to show SharePoint CSOM workflow activities. To simplify the sample code, this version returns the complete Office XML stream to the client and then performs client-side filtering. This is not an efficient means to filter Office XML since the Stream could have a large payload. A production application would move parts of the SharePoint related workflow to a WCF workflow service; thus, enabling the server to get the Office XML stream and return filtered office parts to the client.

Sample ViewPublisher

A ViewPublisher is similar to an interface or abstract class in that they define the properties of a View change. A ViewSubscriber invokes the view change. This decouples the Excel and Word PIA model from the workflow.

Tacking Participant

A Treeview hosted in an Office Task Pane can act as a Workflow Tracking Participant or Subscriber. The example below shows tracking state event data added to a Treeview on the control’s thread.

The next post will start diving into the source code that enables Office Workflow.