Tuesday, 5 May 2015

How to start the workflow for an item using PowerShell / C#

In this article we will be seeing how to start a workflow for an item using c# and powershell

Start a workflow using c#

class Program    {
        static void Main(string[] args)
            using (SPSite site = new SPSite("YourSiteURL"))
                using (SPWeb web = site.RootWeb)
                    SPList list = web.Lists["Test"]; 
                    SPListItem item=list.Items[0];
                    SPWorkflowManager manager = site.WorkflowManager;
                    SPWorkflowAssociation association = list.WorkflowAssociations[0];
                    string data = association.AssociationData;
                    SPWorkflow wf = manager.StartWorkflow(item, association, data, true);

Start a workflow using powershell:

$site=Get-Spsite $siteURL

Hope this helps!!!!

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...