How to create workflows using C# on Sharepoint 2013?

Puneeth, C 81 Reputation points
2022-06-30T06:00:36.173+00:00

I am trying to copy a site on to a different location using code and I could not any code snippet to do the same. I am getting the Workflow associations using the following code but have no clue how to re-create them on the destination site.

public static List<SPWorkflowAssociation> GetAllWorkFlowAssociations(String source)  
        {  
            List<SPWorkflowAssociation> wfas = new List<SPWorkflowAssociation>();  
            using (SPSite site = new SPSite(source))  
            {  
                SPWebCollection webs = site.AllWebs;  
                foreach (SPWeb web in webs)  
                {  
                    foreach (SPList list in web.Lists)  
                    {  
                        SPWorkflowAssociationCollection collection = list.WorkflowAssociations;  
                        foreach(SPWorkflowAssociation wfa in collection){  
                            Console.WriteLine(wfa.Name+" Current list: "+wfa.TaskListTitle+" Author: "+wfa.Author);  
                            wfas.Add(wfa);  
                        }  
                    }  
                }  
            }  
            return wfas;  
        }  
  

can you please help? Thanks.

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,547 questions
SharePoint Workflow
SharePoint Workflow
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Workflow: An orchestrated and repeatable pattern of business activity, enabling data transformation, service provision, and information retrieval.
482 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,111 Reputation points
    2022-07-01T08:49:30.247+00:00

    Hi @Puneeth, C ,

    According to my research and testing, unfortunately, we can start and stop the workflow using CSOM. And get data from workflow by CSOM. But we can not add conditions into workflow by CSOM. In other words, we cannot create the workflow using CSOM.

    Thanks for your understanding.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.