SPContentType.UpdateWorkflowAssociationsOnChildren method (Boolean, Boolean, Boolean, Boolean)

Propagates changes in this content type’s workflow associations to content types that are derived from this content type or to instances of this content type that have been applied to lists, or to both. Optionally marks objects touched by the operation as changed. Also optionally suppresses exceptions that are thrown because a child is either sealed or read-only.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public void UpdateWorkflowAssociationsOnChildren(
	bool bGenerateFullChangeList,
	bool bPushdownDerivedCT,
	bool bPushdownListCTs,
	bool bThrowOnSealedOrReadOnly
)

Parameters

bGenerateFullChangeList
Type: System.Boolean

true to mark all SPContentType objects touched by this operation as changed; false does not.

bPushdownDerivedCT
Type: System.Boolean

true to propagate changes to content types derived from this content type; otherwise false.

bPushdownListCTs
Type: System.Boolean

true to propagate changes to list content types based on this content type; otherwise false.

bThrowOnSealedOrReadOnly
Type: System.Boolean

true to throw an exception on encountering a content type that is sealed or read-only; otherwise false.

ExceptionCondition
SPContentTypeSealedException

The Sealed property of a child of this content type has a value of true.

SPContentTypeReadOnlyException

The ReadOnly property of a child of this content type has a value of true.

Use this method to optionally propagate changes in the parent content type’s workflow associations down to either derived or list versions of the content type, or both. If you pass false as the argument to the bGenerateFullChangeList parameter, SPContentType objects that are touched by this operation are not marked as changed and OnChanged events are not raised. Passing false as the argument to the bThrowOnSealedOrReadOnly parameter suppresses exceptions thrown when changes cannot be written to any child because it is marked as sealed or read-only.

SPSite siteCollection = new SPSite("http://localhost");
SPWeb site = siteCollection.OpenWeb();

SPContentType siteContentType = site.ContentTypes["Test Document"];
string taskListTitle = "Tasks";
string historyListTitle = "Workflow History";
string workflowName = "Red-Yellow-Green";

// Get a template.
SPWorkflowTemplate workflowTemplate = null;
foreach (SPWorkflowTemplate template in site.WorkflowTemplates)
{
    workflowTemplate = template;

    // We'll take a template everyone has.
    if (workflowTemplate.Name == "Three-state") break;
}

// Create an association.
SPWorkflowAssociation workflowAssociation =
    SPWorkflowAssociation.CreateSiteContentTypeAssociation(workflowTemplate,
                                                           workflowName,
                                                           taskListTitle,
                                                           historyListTitle);

// Add the association to the content type or update it if it already exists.
Console.Write"Workflow association {0} has been ", workflowAssociation.Name);
if (siteContentType.WorkflowAssociations.GetAssociationByName(workflowAssociation.Name, site.Locale) == null)
{
    siteContentType.AddWorkflowAssociation(workflowAssociation);
    Console.WriteLine("added.");
}
else
{
    siteContentType.UpdateWorkflowAssociation(workflowAssociation);
    Console.WriteLine("updated.");
}

// Propagate to children of this content type.
siteContentType.UpdateWorkflowAssociationsOnChildren(false,  // Do not generate full change list
                                                     true,   // Push down to derived content types
                                                     true,   // Push down to list content types
                                                     false); // Do not throw an exception if sealed or readonly  

site.Dispose();
siteCollection.Dispose();
Show: