Here are the Steps I've taken:

Create a Workflow (Reusable 2010, Content-Type linked) on any Web, Export it as a .WSP and Deploy it to the Site Collection in question (the Feature is Web Scoped).

Due to functional reasons: Create an SPWeb (subweb) in an EventReceiver

SPWeb subweb = properties.Web.Webs.Add(....);

In the same EventReceiver, activate the Workflow Feature

Guid featureGUID= new Guid("GUID");
if (subweb .Features[featureGUID] == null)
    subweb .Features.Add(featureGUID);

A While later, try to get the SPWorkflowTemplate for that Feature

SPWorkflowTemplate template = web.WorkflowTemplates.GetTemplateByName("Workflow Test", CultureInfo.CurrentCulture);

Since it is a 2010 Workflow, I've also tried *Workflow Test and * Workflow Test, to no success.

This did work a month ago and stopped working once we've added the SharePoint 2013 Workflow Manager to our development server.

At the Point where I'm checking if the template exists, I've stopped the execution and checked the Templates I can add to the List/Content-Type in Question manually, and the Workflow is listed (filtering for Content-Type). I did make sure the other Web has the same Content-Type (It gets inherited down from a Parent Web.

1 Answer 1


There's different Solutions to this depending on the Workflow Platform used(2013, 2010).

2010: My issue was that the basic Workflow feature in the Site Collection was not activated.

2013: web.WorkflowTemplates does not work at all. You will need to use Microsoft.SharePoint.WorkflowServices to get these. Here is some example code to create a subscription:

// Get the ID of the WorkflowDefinition

WorkflowServicesManager wfServiceManager = new WorkflowServicesManager(web);
var wfDeploymentService = wfServiceManager.GetWorkflowDeploymentService();
var wfDefCollection = wfDeploymentService.EnumerateDefinitions(true);

foreach (WorkflowDefinition wfDef in wfDefCollection)
    if (wfDef.DisplayName == workflowName) 
        // Create a new Subscription
        WorkflowSubscriptionService wfSubscriptionService = wfServiceManager.GetWorkflowSubscriptionService();

        WorkflowSubscription newSub = new WorkflowSubscription();
        newSub.DefinitionId = wfDef.Id;
        newSub.Name = wfDef.DisplayName;

        List<String> startOptions = new List<String>();
        newSub.EventTypes = startOptions;

        newSub.SetProperty("HistoryListId", historyList.ID.ToString());
        newSub.SetProperty("TaskListId", taskList.ID.ToString());

        newSub.Enabled = true;

        wfSubscriptionService.PublishSubscriptionForList(newSub, orderList.ID);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.