Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SPContentType.RemoveWorkflowAssociation Method

Windows SharePoint Services 3

Deletes the specified workflow association from the content type’s collection.

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

public void RemoveWorkflowAssociation(
	SPWorkflowAssociation workflowAssociation
)

Parameters

workflowAssociation
Type: Microsoft.SharePoint.Workflow.SPWorkflowAssociation
An SPWorkflowAssociation object that represents the workflow association to delete from the content type’s collection of workflow associations.

The WorkflowAssociations property returns an SPWorkflowAssociationCollection object with the content type’s collection of workflow associations. You can retrieve an association from the collection by using the value of the Id property as an indexer or by passing the workflow association’s name to the GetAssociationByName method.

The following example is a console application that removes the workflow association that is created by the example for AddWorkflowAssociation.

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

namespace Test
{
    class ConsoleApp
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://localhost"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    string ctName = "Test Document";
                    string wfName = "Red-Yellow-Green";

                    SPContentType contentType = web.ContentTypes[ctName];
                    if (null != contentType)
                    {
                        SPWorkflowAssociation wfAssociation =
                            contentType.WorkflowAssociations.GetAssociationByName(wfName, web.Locale);

                        if (null != wfAssociation)
                        {
                            // Remove the workflow association.
                            contentType.RemoveWorkflowAssociation(wfAssociation);
                            Console.WriteLine("The association with {0} workflow has been removed.", wfAssociation.Name);
                        }
                        else
                        {
                            Console.WriteLine("An association with {0} workflow was not found.", wfName);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Content type {0} does not exist.", ctName);
                    }
                }
            }
            Console.Write("\nPress ENTER to continue...");
            Console.ReadLine();
        }
    }
}

Community Additions

ADD
Show:
© 2015 Microsoft