public static void EnsurePublishingWorkflows(SPWeb web, bool useSAMLWorkflow, bool remove) { if (PublishingWeb.IsPublishingWeb(web)) { PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web); if (pubweb != null) { string listNames = GlobalSettingsHelper.GetValue(ListConstants.EnablePublishingApprovalWorkflowOnLists); if (!string.IsNullOrEmpty(listNames)) { string[] lists = listNames.ToLower().Split(new char[] { ',' }); foreach (string listName in lists) { SPList list = null; switch (listName) { case ("pages"): list = pubweb.PagesList; break; case ("images"): list = pubweb.ImagesLibrary; break; case ("documents"): list = pubweb.DocumentsLibrary; break; } if (list != null) { if (remove) { WorkflowHelper2013.RemoveApprovalWorkflowOnList(web, list, useSAMLWorkflow); } else { List <WorkflowHelper2013.WorkflowStartEventType> events = new List <WorkflowHelper2013.WorkflowStartEventType>() { WorkflowHelper2013.WorkflowStartEventType.Manual }; WorkflowHelper2013.EnsureApprovalWorkflowOnList(web, list, events, useSAMLWorkflow); } } } } } } else { throw new SPException("This feature can only be enabled on a Publishing Web. However you can configure the approval workflows thru list workflow settings."); } }
/// <summary> /// Gets the approval workflow settings. /// </summary> /// <param name="web">The web.</param> /// <param name="taskName">Name of the task.</param> /// <returns> /// The dictionary of workflow settings /// </returns> /// <exception cref="Microsoft.SharePoint.SPException"></exception> private static Dictionary <string, string> GetApprovalWorkflowSettings(SPWeb web, string taskName) { Dictionary <string, string> payLoad = new Dictionary <string, string>(); string value = string.Empty; try { value = GlobalSettingsHelper.GetValue(ListConstants.ApprovalWorkflowApproversSharePointGroup); string approvers = ParseContentApproverGroups(web, value); if (approvers.Length == 0) { throw new SPException("No SharePoint Approver Groups found"); } payLoad.Add("Approvers", approvers); } catch (Exception ex) { throw new SPException(string.Format("Error in SharePoint Approver Group resolution{0}{1}", Environment.NewLine, ex.Message), ex); } try { value = GlobalSettingsHelper.GetValue(ListConstants.ApprovalWorkflowDefaultDurationDays); if (!string.IsNullOrEmpty(value)) { payLoad.Add("Duration", value); } } catch { } value = ResourcesHelper.GetLocalizedString("workflow_ApprovalTaskDefaultTitle"); if (!string.IsNullOrEmpty(value)) { payLoad.Add("TaskTitle", string.Format(value, taskName)); } value = ResourcesHelper.GetLocalizedString("workflow_ApprovalTaskAssignedEmailSubject"); if (!string.IsNullOrEmpty(value)) { payLoad.Add("TaskAssignmentEmailSubject", string.Format(value, taskName)); } value = ResourcesHelper.GetLocalizedString("workflow_ApprovalTaskAssignedEmailBodyHtml"); if (!string.IsNullOrEmpty(value)) { payLoad.Add("TaskAssignmentEmailBodyHtml", value); } value = ResourcesHelper.GetLocalizedString("workflow_ApprovalTaskCancelledEmailSubject"); if (!string.IsNullOrEmpty(value)) { payLoad.Add("TaskCancellationEmailSubject", string.Format(value, taskName)); } value = ResourcesHelper.GetLocalizedString("workflow_ApprovalTaskCancelledEmailBodyHtml"); if (!string.IsNullOrEmpty(value)) { payLoad.Add("TaskCancellationEmailBodyHtml", value); } value = ResourcesHelper.GetLocalizedString("workflow_ApprovalTaskOverdueEmailSubject"); if (!string.IsNullOrEmpty(value)) { payLoad.Add("TaskOverdueEmailSubject", string.Format(value, taskName)); } value = ResourcesHelper.GetLocalizedString("workflow_ApprovalTaskOverdueEmailBodyHtml"); if (!string.IsNullOrEmpty(value)) { payLoad.Add("TaskOverdueEmailBodyHtml", value); } value = ResourcesHelper.GetLocalizedString("workflow_approvaltaskstatus_completed"); if (!string.IsNullOrEmpty(value)) { payLoad.Add("TaskCompletionStatus", value); } payLoad.Add("EndonFirstApproval", "true"); payLoad.Add("EnableContentApproval", "true"); return(payLoad); }