I'm trying to add a feedback workflow to several lists with the BaseTemplate 101 via feature activated event receiver. I'm using SharePoint 2013
My problem is, that the first list works fine, but the second fails with the error:
An exception of type 'Microsoft.SharePoint.SPException' occurred in Microsoft.SharePoint.dll but was not handled in user code
Additional information: Exception from HRESULT: 0x80131904
If I leave the first list out, add the workflow to the second it will still fail at the third list and so on...
I already checked the content database, because several other sources said that the database might be full, but it isn't.
This is the code that I'm using in the EventReceiver. I marked the point at the end where the error happens.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
string taskListTitle = "WorkflowTasks";
string historyListTitle = "Workflow History";
SPWorkflowTemplate collectFeedbackWorkflowTemplate = null;
//Initializing with workflow template IDs
Guid collectFeedbackWorkflowTemplateID = new Guid("3bfb07cb-5c6a-4266-849b-8d6711700407");
//Get Lists
SPListCollection lists = web.Lists;
//Getting workflow template based on workflow id
foreach (SPWorkflowTemplate template in web.WorkflowTemplates)
{
string templateName = template.Name;
if (template.Id.Equals(collectFeedbackWorkflowTemplateID))
{
collectFeedbackWorkflowTemplate = template;
}
}
//--------------------------- Create collect feedback workflow association.--------------------------------------
SPWorkflowAssociation collectFeedbackWorkflowAssociation = SPWorkflowAssociation.CreateWebContentTypeAssociation(collectFeedbackWorkflowTemplate,
collectFeedbackWorkflowName,
taskListTitle,
historyListTitle);
//setting to specify that workflow can be started manually
collectFeedbackWorkflowAssociation.AllowManual = true;
//setting to specify that manage lists permissions is required for starting a workflow
if (collectFeedbackWorkflowAssociation.AllowManual)
{
SPBasePermissions emptyMask = SPBasePermissions.EmptyMask;
emptyMask |= SPBasePermissions.ManageLists;
collectFeedbackWorkflowAssociation.PermissionsManual = emptyMask;
}
//setting to specify that workflow will be automatically started whenever a new item is added
collectFeedbackWorkflowAssociation.AutoStartCreate = false;
//setting to specify that workflow will be automatically started whenever an item is changed/edited
collectFeedbackWorkflowAssociation.AutoStartChange = false;
//Adding workflow association to list
foreach (SPList list in lists)
{
if ((int)list.BaseTemplate == 101)
{
// Here is the point where it fails
list.WorkflowAssociations.Add(collectFeedbackWorkflowAssociation);
}
}
}
Does anyone have an idea why I can add the workflow to one list but fails at the next?