About Me

My photo
a Dynamic and Energetic guy.....

Friday, October 31, 2008

Programatically Add a WORKFLOW to a SPList

private void setWorkflow()
{
try
{
SPWeb web = site.RootWeb;
SPList refList = web.Lists["DepartmentDetails"];

SPWorkflowManager wfManager = site.WorkflowManager;
SPWorkflowTemplateCollection wfTemplates = wfManager.GetWorkflowTemplatesByCategory(web, null);
string test = wfTemplates[0].Name;
test = wfTemplates[1].Name;
test = wfTemplates[2].Name;
test = wfTemplates[3].Name;
test = wfTemplates[4].Name;
SPList taskList = web.Lists["Tasks"];

Guid WorkflowHistoryGuid = web.Lists.Add("HistoryOfWorkflow", "description History", SPListTemplateType.WorkflowHistory);
SPList HistoryList = web.Lists[WorkflowHistoryGuid];
//SPList HistoryList = web.Lists["HistoryOfWorkflow"];

SPWorkflowTemplate wfTempl = wfTemplates.GetTemplateByName("Approval", CultureInfo.CurrentCulture);
SPWorkflowAssociation wfAssocite = SPWorkflowAssociation.CreateListAssociation(wfTempl, wfTempl.Name, taskList, HistoryList);

wfAssocite.AutoStartCreate = true;
refList.AddWorkflowAssociation(wfAssocite);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

No comments:

My Masters