Get All Workflow Names Including Content Type Reference In SharePoint

Started using this handy method at the advice of a co-worker:

[csharp]

         public static List<string> GetWorkflowNames(SPList list)
        {
            List<string> workflowNames = new List<string>();
            if (list != null)
            {
                foreach (SPWorkflowAssociation workflowAssociation in list.WorkflowAssociations.Cast<SPWorkflowAssociation>().Where(workflowAssociation => !workflowNames.Contains(workflowAssociation.Name)))
                {
                    workflowNames.Add(workflowAssociation.Name);
                }
                foreach (SPWorkflowAssociation workflowAssociation in
                    from SPContentType type in list.ContentTypes
                    from SPWorkflowAssociation workflowAssociation in type.WorkflowAssociations
                    where !workflowNames.Contains(workflowAssociation.Name)
                    select workflowAssociation)
                {
                    workflowNames.Add(workflowAssociation.Name);
                }
            }
            return workflowNames;
        }

[/csharp]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *