Special thanks to Vadim Tabakman (working in Nintex) who gave this idea to develop this reusable tool.

As you know Nintex workflows are easy to build and customize. But, sometimes we have to deploy a common/reusable nintex workflow to more than one lists or document libraries in a site collection. In this case, when we got a requirement to change something in workflow then we will be in trouble like how to publish the new changed workflow to all libraries.

Imagine we have 100 sub sites with 8 lists / document libraries. It means we have to publish the nintex workflow to 100 * 8 = 800 lists and libraries. Which is not at all possible with the manual upload process? So, the only way would be writing code to publish them automatically by running it.

The solution which I have written needs the updated nintex workflow file [.NWF] as input, web url and site url. It loops through all sites in the site collection and updates the each and every library/lists with the updated nintex file successfully.

Code Sample

private static void UpdateWokflow()
{
ArrayList chkedlist = new ArrayList(); // To capture the list names where we have import workflow
try
{
for (int i = 0; i < chkList.Items.Count; i++)
{
if (chkList.GetItemChecked(i))
{
chkedlist.Add(chkList.Items [i].ToString());
}
}

        string siteid = ddSitecollection.SelectedValue.ToString();
        Guid MyGuid = new Guid(siteid);

        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            SPSite dsite = new SPSite(MyGuid);
            SPWeb web = dsite.OpenWeb(ddSubSiteCollcetion.SelectedText.ToString());
            web.AllowUnsafeUpdates = true;
            byte[] rawData = File.ReadAllBytes(txtFiles.Text + "" + ddWFName.SelectedItem.ToString());
            NintexWorkflowWS.NintexWorkflowWS ws = new NintexWorkflowWS.NintexWorkflowWS();
            ws.Url = web.Url + "/_vti_bin/NintexWorkflow/workflow.asmx";
            ws.UseDefaultCredentials = true;
            string workflowname = string.Empty;

            foreach(string listName in chkedlist)
            {
                if (!chknewwf.Checked) // check to preserve the same name for the workflow or not
                {
                    workflowname = listName + "-" + ddWFName.SelectedItem.ToString().Split('.')[0] + "Workflow";
                }
                else
                {
                    workflowname = listName + "-" + txtnewworkflowname.Text + "Workflow";
                }

                //Publish the workflow
                ws.PublishFromNWF(rawData, listName, workflowname, true);
            }

            web.AllowUnsafeUpdates = false;
        });

        MessageBox.Show("Success");
    }

    catch(Exception exception)
    {
        MessageBox.Show("An error occured while trying to publish the workflows: " + exception.Message);
    }

}