Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

First, let me share with you some backgound info on my current environment. I have a content type named "Contract" defined in my root site collection. Then I created a state machine workflow named "Contract Management Workflow" for that "Contract" content type. The Shared Documents library in my root site collection has been configured to allow management of content types and the "Contract" content type was added to the library. The current workflow settings for the Shared Documents library at this point is that the Document content type is not associated with any workflow and the "Contract" content type is associated with the "Contract Management Workflow" (http://screencast.com/t/j1tX9V5eN).

At this point everything works fine the way I like it. I can upload a new document to the Shared Documents library and specify that the content type is of type "Contract". Once the document is uploaded I can select the document and start the "Contract Management Workflow".

In the root site collection I have a WebPart that creates sub sites on demand. When the sub site is created I want to inherit the "Contract" content type and the "Contract Management Workflow" from my root site collection. Programatically, I think I got it to inherit the content type and the workflow (http://screencast.com/t/K0OSsKPJ), but I'm still missing something because when I upload a document in the new sub site and specify the content type as "Contract", it doesn't allow me to start the "Contract Management Workflow". SharePoint tells me that "There are no workflows currently available to start on this item." even though the library's workflow settting indicates that the "Contract Management Workflow" is associated with the "Contract" content type.

Here is the code for the WebPart which creates the sub site:

SPWeb rootSiteCollection = SPContext.Current.Web;
SPContentType contractContentType = rootSiteCollection.ContentTypes["Contract"];
SPWeb newSubSite = rootSiteCollection.Webs.Add(txtSiteAbbreviation.Text.Trim(), txtSiteName.Text.Trim(), siteDescription, 1033, "STS#0", false, false);
SPList newSubSiteShareDocuments = newSubSite.Lists["Shared Documents"];
newSubSiteShareDocuments.ContentTypesEnabled = true;

// attach the workflow to the content type in our new sub site
SPContentType newSubSiteContractContentType = newSubSiteShareDocuments.ContentTypes["Contract"];
string workflowTaskList = "Tasks";
string workflowHistoryList = "Workflow History";
string workflowName = "Contract Management Workflow";

SPWorkflowTemplate workflowTemplate = null;
foreach (SPWorkflowTemplate template in rootSiteCollection.WorkflowTemplates)
    if (template.Name != "Contract Management Workflow") continue;

    workflowTemplate = template;

SPWorkflowAssociation workflowAssociation = newSubSiteContractContentType.WorkflowAssociations.GetAssociationByName(workflowName, newSubSite.Locale);
if (workflowAssociation == null)
    // this branch of the if statement never get executed. workflowAssociation is never null for me
    workflowAssociation = SPWorkflowAssociation.CreateSiteContentTypeAssociation(workflowTemplate,

    // this always gets executed
share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.