SPList myList = null ; // workflow string myListName = null ; // SPList historyList = null ; // workflow SPList taskList = null ; // workflow string workflowTemplateGuid = null ; // Guid worklfow SPWorkflowTemplate workflowTemplate = null ; // Workflow SPWorkflowAssociation workflowAssociation = null ; // workflow string workflowAssocName = null ; // workflow
* This source code was highlighted with Source Code Highlighter .
SPList myList = null ; // workflow string myListName = null ; // SPList historyList = null ; // workflow SPList taskList = null ; // workflow string workflowTemplateGuid = null ; // Guid worklfow SPWorkflowTemplate workflowTemplate = null ; // Workflow SPWorkflowAssociation workflowAssociation = null ; // workflow string workflowAssocName = null ; // workflow
* This source code was highlighted with Source Code Highlighter .SPList myList = null ; // workflow string myListName = null ; // SPList historyList = null ; // workflow SPList taskList = null ; // workflow string workflowTemplateGuid = null ; // Guid worklfow SPWorkflowTemplate workflowTemplate = null ; // Workflow SPWorkflowAssociation workflowAssociation = null ; // workflow string workflowAssocName = null ; // workflow
* This source code was highlighted with Source Code Highlighter .SPList myList = null ; // workflow string myListName = null ; // SPList historyList = null ; // workflow SPList taskList = null ; // workflow string workflowTemplateGuid = null ; // Guid worklfow SPWorkflowTemplate workflowTemplate = null ; // Workflow SPWorkflowAssociation workflowAssociation = null ; // workflow string workflowAssocName = null ; // workflow
* This source code was highlighted with Source Code Highlighter .SPList myList = null ; // workflow string myListName = null ; // SPList historyList = null ; // workflow SPList taskList = null ; // workflow string workflowTemplateGuid = null ; // Guid worklfow SPWorkflowTemplate workflowTemplate = null ; // Workflow SPWorkflowAssociation workflowAssociation = null ; // workflow string workflowAssocName = null ; // workflow
* This source code was highlighted with Source Code Highlighter .SPList myList = null ; // workflow string myListName = null ; // SPList historyList = null ; // workflow SPList taskList = null ; // workflow string workflowTemplateGuid = null ; // Guid worklfow SPWorkflowTemplate workflowTemplate = null ; // Workflow SPWorkflowAssociation workflowAssociation = null ; // workflow string workflowAssocName = null ; // workflow
* This source code was highlighted with Source Code Highlighter .SPList myList = null ; // workflow string myListName = null ; // SPList historyList = null ; // workflow SPList taskList = null ; // workflow string workflowTemplateGuid = null ; // Guid worklfow SPWorkflowTemplate workflowTemplate = null ; // Workflow SPWorkflowAssociation workflowAssociation = null ; // workflow string workflowAssocName = null ; // workflow
* This source code was highlighted with Source Code Highlighter .SPList myList = null ; // workflow string myListName = null ; // SPList historyList = null ; // workflow SPList taskList = null ; // workflow string workflowTemplateGuid = null ; // Guid worklfow SPWorkflowTemplate workflowTemplate = null ; // Workflow SPWorkflowAssociation workflowAssociation = null ; // workflow string workflowAssocName = null ; // workflow
* This source code was highlighted with Source Code Highlighter .SPList myList = null ; // workflow string myListName = null ; // SPList historyList = null ; // workflow SPList taskList = null ; // workflow string workflowTemplateGuid = null ; // Guid worklfow SPWorkflowTemplate workflowTemplate = null ; // Workflow SPWorkflowAssociation workflowAssociation = null ; // workflow string workflowAssocName = null ; // workflow
* This source code was highlighted with Source Code Highlighter .SPList myList = null ; // workflow string myListName = null ; // SPList historyList = null ; // workflow SPList taskList = null ; // workflow string workflowTemplateGuid = null ; // Guid worklfow SPWorkflowTemplate workflowTemplate = null ; // Workflow SPWorkflowAssociation workflowAssociation = null ; // workflow string workflowAssocName = null ; // workflow
* This source code was highlighted with Source Code Highlighter .
- myListName = "My list name" ;
- workflowAssocName = "My Workflow" ;
* This source code was highlighted with Source Code Highlighter .
- workflowTemplateGuid = "BAD855B1-32CE-4bf1-A29E-463678304E1A" ;
- workflowTemplate = web.WorkflowTemplates [ new Guid (workflowTemplateGuid)];
* This source code was highlighted with Source Code Highlighter .
- // Try to get a list of workflow history
- try
- {
- historyList = web.Lists [ "Workflow History" ];
- }
- catch (ArgumentException exc)
- {
- // Create a workflow history list
- Guid listGuid = web.Lists.Add ( "Workflow History" , "" , SPListTemplateType.WorkflowHistory);
- historyList = web.Lists [listGuid];
- historyList.Hidden = true ;
- historyList.Update ();
- }
* This source code was highlighted with Source Code Highlighter .
- workflowTemplate = web.WorkflowTemplates.GetTemplateByName ( "Template name" , System.Globalization.CultureInfo.CurrentCulture);
* This source code was highlighted with Source Code Highlighter .
- // Trying to get a list of tasks for workflow
- try
- {
- taskList = web.Lists [ "Workflow Tasks" ];
- }
- catch (ArgumentException exc)
- {
- // Create a task list for workflow
- Guid listGuid = web.Lists.Add ( "Workflow Tasks" , "" , SPListTemplateType.Tasks);
- taskList = web.Lists [listGuid];
- taskList.Hidden = true ;
- taskList.Update ();
- }
* This source code was highlighted with Source Code Highlighter .
- // Enable unsafe updates for the site (web)
- web.AllowUnsafeUpdates = true ;
- try
- {
- // Create a workflow association
- workflowAssociation = SPWorkflowAssociation.CreateListAssociation (workflowTemplate, workflowAssocName, taskList, historyList);
- // Set workflow parameters
- workflowAssociation.AllowManual = false ;
- workflowAssociation.AutoStartCreate = true ;
- workflowAssociation.AutoStartChange = false ;
- // Link workflow with the list
- myList.AddWorkflowAssociation (workflowAssociation);
- // Activate the association
- workflowAssociation.Enabled = true ;
- }
- finally
- {
- web.AllowUnsafeUpdates = false ;
- }
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/59661/
All Articles