SharePoint workflow does not start for automatically uploaded documents

被刻印的时光 ゝ 提交于 2020-01-06 08:07:56

问题


I have a service that automatically uploads documents to a SharePoint 2013 Document Library. I created a simple workflow that starts when a new item is created and just sends an email notification; however, the workflow only starts when I manually add a document and not when it's uploaded by the service. Thank you in advance for any ideas on how to resolve it.


回答1:


If you have attached your workflow to the list, the workflow should be triggered automatically. I found some case like this before. please check [here][1]

[1]: https://sharepoint.stackexchange.com/questions/62371/workflow-not-triggered-via-custom-webpart-but-works-if-add-item-from-ui .




回答2:


I had to add some code to start a workflow after the app does its stuff:

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

static void StartWorkflow(SPListItem listItem, SPSite spSite, string wfName)
{
    SPList parentList = listItem.ParentList;
    SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;
    foreach (SPWorkflowAssociation association in associationCollection)
    {
        if (association.Name == wfName)
        {
            association.AutoStartChange = true;
            association.AutoStartCreate = false;
            association.AssociationData = string.Empty;
            spSite.WorkflowManager.StartWorkflow(listItem, association, association.AssociationData);
        }
    }
}


来源:https://stackoverflow.com/questions/20861247/sharepoint-workflow-does-not-start-for-automatically-uploaded-documents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!