I found another way using SharePoint Designer workflow. You can trigger a workflow to run programmatically and also supply information to the workflow and set the initiation values. Here's the code to start a workflow:
/// /// Method to handle starting the appropriate Workflow as specified by the Site Collection Workflow Name property /// private void StartWorkflow() { SPWorkflowAssociation wfa = SPContext.Current.Web.WorkflowAssociations.GetAssociationByName(this.SiteCollectionWorkflowName, CultureInfo.InvariantCulture); wfa.AssociationData = this.GetWorkflowInitiationData(); SPContext.Current.Site.WorkflowManager.StartWorkflow(null, wfa, this.GetWorkflowInitiationData(), SPWorkflowRunOptions.Asynchronous); } /// /// Method to construct the Workflow Initiation/Association Data /// /// private String GetWorkflowInitiationData() { String schema = " "xmlns:dms=\"http://schemas.microsoft.com/office/2009/documentManagement/types\" " + "xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\" " + "xmlns:q=\"http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields\" " + "xmlns:d=\"http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields\" " + "xmlns:ma=\"http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes\" " + "xmlns:pc=\"http://schemas.microsoft.com/office/infopath/2007/PartnerControls\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + " " StringBuilder sb = new StringBuilder(); sb.AppendFormat(" sb.AppendFormat(" sb.AppendFormat(" sb.AppendFormat(" sb.AppendFormat(" sb.AppendFormat(" return String.Format(schema, sb.ToString()); } |
1 comment:
Nice code sample, thank you for posting.
Post a Comment