This documentation is archived and is not being maintained.

SPContentType.UpdateWorkflowAssociation Method

Windows SharePoint Services 3

Updates the specified workflow association.

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

public void UpdateWorkflowAssociation(
	SPWorkflowAssociation workflowAssociation
)

Parameters

workflowAssociation
Type: Microsoft.SharePoint.Workflow.SPWorkflowAssociation
An SPWorkflowAssociation object that has been updated.

ExceptionCondition
ArgumentNullException

The SPWorkflowAssociation object is a null reference (Nothing in Visual Basic).

If the workflow association that you are updating does not exist in the content type’s collection, this method does nothing. You can test for an association’s existence by calling the GetAssociationByNamemethod. If the return value of that method is a null reference (Nothing in Visual Basic), then the association is not in the collection. The following example demonstrates this technique.

if (contentType.WorkflowAssociations.GetAssociationByName(workflowAssociation.Name, site.Locale) == null)
{
    contentType.AddWorkflowAssociation(workflowAssociation);
}
else
{
    contentType.UpdateWorkflowAssociation(workflowAssociation);
}

The following example is a console application that gets a reference to a particular workflow association in a collection, changes one of the association’s property values, and then updates the association in the collection.

The code for the example assumes the existence of a site content type that has a workflow association named “Approval.”

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;

namespace Test
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            Console.WriteLine();
            SPSite oSPSite = new SPSite("http://localhost");
            SPWeb oSPWeb = oSPSite.OpenWeb();

            string contentTypeName = "Your Content Type Name Here";
            SPContentType contentType;
            string workflowAssociationName = "Approval";
            SPWorkflowAssociation workflowAssociation;

            // Get a reference to a site content type.
            contentType = oSPWeb.ContentTypes[contentTypeName];
            Console.WriteLine("Content type: " + contentType.Name);

            // Get a workflow association for the content type.
            workflowAssociation = contentType.WorkflowAssociations.GetAssociationByName(workflowAssociationName,
                                                                                        oSPWeb.Locale);
            // Print the current value of a property.
            Console.WriteLine("Workflow association: " + workflowAssociation.Name);
            Console.WriteLine("Old value of AutoStartCreate: " + workflowAssociation.AutoStartCreate.ToString());

            // Change the property value.
            bool bState = workflowAssociation.AutoStartCreate;
            workflowAssociation.AutoStartCreate = !bState;

            // Update the association.
            contentType.UpdateWorkflowAssociation(workflowAssociation);

            // Verify the change.
            Console.WriteLine("New value of AutoStartCreate: " + workflowAssociation.AutoStartCreate.ToString());

            oSPWeb.Dispose();
            oSPSite.Dispose();

            Console.WriteLine();
            Console.Write("Press ENTER to continue...");
            Console.ReadLine();
        }
    }
}
Show: